sending a structure of integers over a networkstream
sending a structure of integers over a networkstream
sending a structure of integers over a networkstream
sending a structure of integers over a networkstream
sending a structure of integers over a networkstream
sending a structure of integers over a networkstream sending a structure of integers over a networkstream sending a structure of integers over a networkstream sending a structure of integers over a networkstream sending a structure of integers over a networkstream sending a structure of integers over a networkstream sending a structure of integers over a networkstream sending a structure of integers over a networkstream
sending a structure of integers over a networkstream sending a structure of integers over a networkstream
sending a structure of integers over a networkstream
Go Back  Xtreme Visual Basic Talk > > > sending a structure of integers over a networkstream


Reply
 
Thread Tools Display Modes
  #1  
Old 10-11-2004, 04:23 AM
investjuun investjuun is offline
Newcomer
 
Join Date: Oct 2004
Posts: 1
Default sending a structure of integers over a networkstream


public structure foobar
public foo as integer
public bar as integer
end structure

dim fb as foobar

fb.foo = 123
fb.bar = 456

i need to send this structure over the network using networkstream and i don't want to change each integer to a string and then back again on the other machine, as it's not efficient enough for the amount of realtime data (much, MUCH more than 'foobar' above) that i'm pumping across.

i know that it's possible to send the raw binary contents of a structure; i just don't know how.

thanks.

- philip
Reply With Quote
  #2  
Old 10-13-2004, 05:40 PM
excaliber's Avatar
excalibersending a structure of integers over a networkstream excaliber is offline
Senior Contributor

* Expert *
 
Join Date: Nov 2002
Location: Ohio, USA
Posts: 1,828
Default

Layer a BinaryWriter object on top of the NetworkStream.

Code:
Dim nStream as New NetworkStream(stream) Dim bWriter as New System.IO.BinaryWriter(nStream) bWriter.Write(myData) bWriter.Flush bWriter.Close

Alternatively, you could also look into VB.Net's serialization and deserialization objects. Serialization can take your objects (structures, classes, etc) and serialize it into binary data (or XML, your pick) to send wherever, and can reconstruct it by deserializing it.

http://www.freevbcode.com/ShowCode.asp?ID=4382
http://www.devasp.net/net/search/dis...tegory331.html
Reply With Quote
  #3  
Old 10-28-2004, 04:23 PM
mdashali mdashali is offline
Newcomer
 
Join Date: Jul 2004
Posts: 14
Default

What is myData?
I tried passing my structure to the write function but generates error.

Can you please throw some light in to this.
Is there any other reference which is specific to serialization for networkstream?

Thanks a bunch!
Reply With Quote
  #4  
Old 10-28-2004, 04:57 PM
excaliber's Avatar
excalibersending a structure of integers over a networkstream excaliber is offline
Senior Contributor

* Expert *
 
Join Date: Nov 2002
Location: Ohio, USA
Posts: 1,828
Default

Quote:
Originally Posted by mdashali
What is myData?
I tried passing my structure to the write function but generates error.

Can you please throw some light in to this.
Is there any other reference which is specific to serialization for networkstream?

Thanks a bunch!

myData is any type of data (int, string, byte, etc). Check the overloads list on the method to see what can be written.

If you need the entire structure to go over, you need to serialize it (which turns the class/object into a string or array of bytes, which can then be sent over the networkstream). Here are some more links on serialization:

http://visualbasic.about.com/library...vbnet10302.htm
http://users.skynet.be/wvdd2/Persist...n_in__net.html
http://www.devx.com/dotnet/Article/16032
http://home.att.net/~codeLibrary/XML...lization_p.htm
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
sending a structure of integers over a networkstream
sending a structure of integers over a networkstream
sending a structure of integers over a networkstream sending a structure of integers over a networkstream
sending a structure of integers over a networkstream
sending a structure of integers over a networkstream
sending a structure of integers over a networkstream sending a structure of integers over a networkstream sending a structure of integers over a networkstream sending a structure of integers over a networkstream sending a structure of integers over a networkstream sending a structure of integers over a networkstream sending a structure of integers over a networkstream
sending a structure of integers over a networkstream
sending a structure of integers over a networkstream
 
sending a structure of integers over a networkstream
sending a structure of integers over a networkstream
 
-->