473,386 Members | 1,821 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,386 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 1545
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.