473,320 Members | 2,003 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Passing objects with sockets

I'm trying to write an helper class that allows me to serialize objects to a
socket (or a NetworkStream). I know there are plenty of .NET classes that
help me to serialize object to an array of byte, but I can't undestand how I
can send a block of bytes and being sure the receiver will receive only this
block....I mean, if I write the bytes to a NetworkStream the receiver will
get a stream of bytes and he won't have any way to know how to "split" the
data. Am I supposed to build a protocol, using a special byte to mark the
beginning and the end of every "message" (in this case I should stuff the
bytes before sending)?

I hope I've explained well what I would like to do

Thank you for your help

Seba
Jul 21 '05 #1
5 1542
well, you could if you want to.
but I think you might be interested by remoting !!

which is the .NET RPC mechanism......
"cold" <co****@libero.it> wrote in message
news:e1**************@TK2MSFTNGP14.phx.gbl...
I'm trying to write an helper class that allows me to serialize objects to
a socket (or a NetworkStream). I know there are plenty of .NET classes
that help me to serialize object to an array of byte, but I can't
undestand how I can send a block of bytes and being sure the receiver will
receive only this block....I mean, if I write the bytes to a NetworkStream
the receiver will get a stream of bytes and he won't have any way to know
how to "split" the data. Am I supposed to build a protocol, using a
special byte to mark the beginning and the end of every "message" (in this
case I should stuff the bytes before sending)?

I hope I've explained well what I would like to do

Thank you for your help

Seba

Jul 21 '05 #2
You can use either:

- fixed-size messages
- variable-size messages with the size in each message
- a special separator at the end of each message.

--

Best regards,

Carlos J. Quintero

MZ-Tools: Productivity add-ins for Visual Studio .NET, VB6, VB5 and VBA
You can code, design and document much faster.
Free resources for add-in developers:
http://www.mztools.com

"cold" <co****@libero.it> escribió en el mensaje
news:e1**************@TK2MSFTNGP14.phx.gbl...
I'm trying to write an helper class that allows me to serialize objects to
a socket (or a NetworkStream). I know there are plenty of .NET classes
that help me to serialize object to an array of byte, but I can't
undestand how I can send a block of bytes and being sure the receiver will
receive only this block....I mean, if I write the bytes to a NetworkStream
the receiver will get a stream of bytes and he won't have any way to know
how to "split" the data. Am I supposed to build a protocol, using a
special byte to mark the beginning and the end of every "message" (in this
case I should stuff the bytes before sending)?

I hope I've explained well what I would like to do

Thank you for your help

Seba

Jul 21 '05 #3
And which separator can I use? I mean, I can't be sure the character I'll
use won't be present in the content of the stream of bytes I'm sending. I
suppose I have to stuff the bytes...any suggestion?

thanks

Seba

"Carlos J. Quintero [.NET MVP]" <ca*****@NOSPAMsogecable.com> ha scritto nel
messaggio news:%2****************@TK2MSFTNGP09.phx.gbl...
You can use either:

- fixed-size messages
- variable-size messages with the size in each message
- a special separator at the end of each message.

--

Best regards,

Carlos J. Quintero

MZ-Tools: Productivity add-ins for Visual Studio .NET, VB6, VB5 and VBA
You can code, design and document much faster.
Free resources for add-in developers:
http://www.mztools.com

"cold" <co****@libero.it> escribió en el mensaje
news:e1**************@TK2MSFTNGP14.phx.gbl...
I'm trying to write an helper class that allows me to serialize objects
to a socket (or a NetworkStream). I know there are plenty of .NET classes
that help me to serialize object to an array of byte, but I can't
undestand how I can send a block of bytes and being sure the receiver
will receive only this block....I mean, if I write the bytes to a
NetworkStream the receiver will get a stream of bytes and he won't have
any way to know how to "split" the data. Am I supposed to build a
protocol, using a special byte to mark the beginning and the end of every
"message" (in this case I should stuff the bytes before sending)?

I hope I've explained well what I would like to do

Thank you for your help

Seba


Jul 21 '05 #4
For binary messages there is no safe separator. For text messages, you can
use some sequence of characters that are not part of your protocol.

In general, it's better to include the size in the message header. It will
perform better than checking each byte to find separators...

--

Best regards,

Carlos J. Quintero

MZ-Tools: Productivity add-ins for Visual Studio .NET, VB6, VB5 and VBA
You can code, design and document much faster.
Free resources for add-in developers:
http://www.mztools.com

"cold" <co****@libero.it> escribió en el mensaje
news:%2***************@TK2MSFTNGP09.phx.gbl...
And which separator can I use? I mean, I can't be sure the character I'll
use won't be present in the content of the stream of bytes I'm sending. I
suppose I have to stuff the bytes...any suggestion?

thanks

Seba


Jul 21 '05 #5
you obviously has to pass the size of the date first, in the message header
so you should serialize to a MemoryStream first, get the byt array, then
construct you message with a simple header, I would say

MSG:
| MSG type (1 byte) | MSG size (4 bytes) | MSG data (your serialized object,
"n" bytes specified in size) |

but why not use remoting?
it's a perfect high level, object oriented, .NET specific, interprocess
communication protocol/tool

"cold" <co****@libero.it> wrote in message
news:%2***************@TK2MSFTNGP09.phx.gbl...
And which separator can I use? I mean, I can't be sure the character I'll
use won't be present in the content of the stream of bytes I'm sending. I
suppose I have to stuff the bytes...any suggestion?

thanks

Seba

"Carlos J. Quintero [.NET MVP]" <ca*****@NOSPAMsogecable.com> ha scritto
nel messaggio news:%2****************@TK2MSFTNGP09.phx.gbl...
You can use either:

- fixed-size messages
- variable-size messages with the size in each message
- a special separator at the end of each message.

--

Best regards,

Carlos J. Quintero

MZ-Tools: Productivity add-ins for Visual Studio .NET, VB6, VB5 and VBA
You can code, design and document much faster.
Free resources for add-in developers:
http://www.mztools.com

"cold" <co****@libero.it> escribió en el mensaje
news:e1**************@TK2MSFTNGP14.phx.gbl...
I'm trying to write an helper class that allows me to serialize objects
to a socket (or a NetworkStream). I know there are plenty of .NET
classes that help me to serialize object to an array of byte, but I
can't undestand how I can send a block of bytes and being sure the
receiver will receive only this block....I mean, if I write the bytes to
a NetworkStream the receiver will get a stream of bytes and he won't
have any way to know how to "split" the data. Am I supposed to build a
protocol, using a special byte to mark the beginning and the end of
every "message" (in this case I should stuff the bytes before sending)?

I hope I've explained well what I would like to do

Thank you for your help

Seba



Jul 21 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Dan | last post by:
Hello Has anybody tried to open a socket to connect to a server on page a.php and then passing it throung a session variable and getting it back at page b.php and use it there. Ive tried that...
11
by: Mike M | last post by:
Is it possible? In the parent process, I have a socket that binds, listens and then accepts new connections (which creates new sockets in the process). I want to be able to pass some of these new...
3
by: domeceo | last post by:
can anyone tell me why I cannot pass values in a setTimeout function whenever I use this function it says "menu is undefined" after th alert. function imgOff(menu, num) { if (document.images) {...
6
by: Scott Zabolotzky | last post by:
I'm trying to pass a custom object back and forth between forms. This custom object is pulled into the app using an external reference to an assembly DLL that was given to me by a co-worker. A...
2
by: Michael Isaacs | last post by:
Is there any way to share an object or variable between applications other than through .NET remoting? Also, if this is the only way, what kind of overhead is there for storage (memory) and speed...
1
by: cold | last post by:
I'm trying to write an helper class that allows me to serialize objects to a socket (or a NetworkStream). I know there are plenty of .NET classes that help me to serialize object to an array of...
12
by: manochavishal | last post by:
Hi, I am having strange problem in my Program. I cannot paste the whole program as it is huge so just pasting the lines i think are necessary. I am passing a integer array pointer to a...
1
by: martin | last post by:
This code compiles (this is how it should work): Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); This code does not compile (passing an int instead of...
2
by: william.w.oneill | last post by:
I have an application that takes a few command line parameters. As recommended by others in this group, I'm using a named mutex to ensure that only one instance of the application is running. My...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.