473,385 Members | 1,587 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,385 software developers and data experts.

Sockets and Serialization

Hello, I've got a client server app that passes C# objects back and forth
using TCP/IP Async Sockets and Serialization. Works great in the lab, but
when I try it on a the internet or through a slower dial-up, the receive
callback is not always receiving what I wrote. Analyzing this I see that
there is not always a one to one send data/receive data situation. The data
seems to come over but comes over in multiple receive callbacks. Since I am
passing C# objects, when I go to deserialize them, they error out. (usually
with a end of stream error).

The question is, how do I get the BeginReceive to only callback when all of
the data is there and not chunk it up?? I would hate to have to gooberize the
code to detect short packets and paste them together on the other end.

TIA, John Hoffman

Jul 21 '05 #1
3 1918
I've just dealt with this myself though I wanted to define the end of a file
or message but I think you can employ a similar strategy. Are you doing the
serialising yourself or using the Binary / SOAP formatter? After many
attempts to come up with a solution that worked on all networks I ended up
taking control of serialisation and wrapping each transaction (in your case
object) in an XML-esque tag for ease of parsing at the rx end. This has the
added advantage that any meta information can be added to this tag if you
find that you need it.

Upon each EndRecieve I scan backwards from the end of the rx'ed bytes
looking for ">" if I don't find it I copy the bytes into a new array and
stick it on a queue and go back to BeginRead. If however I do find it then I
check the preceding bytes match </object> (you may have to peek the previous
buffer on the queue if you have received a very few) should it transpire
that the end has been reached dequeue all the buffered buffers (!) into a
memorystream, than add the last buffer and raise your event. Note also that
I used a ThreadPool thread to raise this event so that I could get back to
BeginRecieve ASAP rather than waiting for a potentially long running event
handler to complete.

HTH

"John Hoffman" <John Ho*****@discussions.microsoft.com> wrote in message
news:BC**********************************@microsof t.com...
Hello, I've got a client server app that passes C# objects back and forth
using TCP/IP Async Sockets and Serialization. Works great in the lab, but
when I try it on a the internet or through a slower dial-up, the receive
callback is not always receiving what I wrote. Analyzing this I see that
there is not always a one to one send data/receive data situation. The
data
seems to come over but comes over in multiple receive callbacks. Since I
am
passing C# objects, when I go to deserialize them, they error out.
(usually
with a end of stream error).

The question is, how do I get the BeginReceive to only callback when all
of
the data is there and not chunk it up?? I would hate to have to gooberize
the
code to detect short packets and paste them together on the other end.

TIA, John Hoffman

Jul 21 '05 #2
.......yeah. pretty much what you wanted to avoid ;-)

"Stelrad Doulton" <___@____.com> wrote in message
news:Qe**************@newsfe1-gui.ntli.net...
I've just dealt with this myself though I wanted to define the end of a
file or message but I think you can employ a similar strategy. Are you
doing the serialising yourself or using the Binary / SOAP formatter?
After many attempts to come up with a solution that worked on all networks
I ended up taking control of serialisation and wrapping each transaction
(in your case object) in an XML-esque tag for ease of parsing at the rx
end. This has the added advantage that any meta information can be added
to this tag if you find that you need it.

Upon each EndRecieve I scan backwards from the end of the rx'ed bytes
looking for ">" if I don't find it I copy the bytes into a new array and
stick it on a queue and go back to BeginRead. If however I do find it then
I check the preceding bytes match </object> (you may have to peek the
previous buffer on the queue if you have received a very few) should it
transpire that the end has been reached dequeue all the buffered buffers
(!) into a memorystream, than add the last buffer and raise your event.
Note also that I used a ThreadPool thread to raise this event so that I
could get back to BeginRecieve ASAP rather than waiting for a potentially
long running event handler to complete.

HTH

"John Hoffman" <John Ho*****@discussions.microsoft.com> wrote in message
news:BC**********************************@microsof t.com...
Hello, I've got a client server app that passes C# objects back and forth
using TCP/IP Async Sockets and Serialization. Works great in the lab, but
when I try it on a the internet or through a slower dial-up, the receive
callback is not always receiving what I wrote. Analyzing this I see that
there is not always a one to one send data/receive data situation. The
data
seems to come over but comes over in multiple receive callbacks. Since I
am
passing C# objects, when I go to deserialize them, they error out.
(usually
with a end of stream error).

The question is, how do I get the BeginReceive to only callback when all
of
the data is there and not chunk it up?? I would hate to have to gooberize
the
code to detect short packets and paste them together on the other end.

TIA, John Hoffman


Jul 21 '05 #3
Thanks for confirming this. I ended up wrapping the object. Still hard to
believe that the Socket class can't be setup to do a send/receive on a one to
one basis...

"Stelrad Doulton" wrote:
.......yeah. pretty much what you wanted to avoid ;-)

"Stelrad Doulton" <___@____.com> wrote in message
news:Qe**************@newsfe1-gui.ntli.net...
I've just dealt with this myself though I wanted to define the end of a
file or message but I think you can employ a similar strategy. Are you
doing the serialising yourself or using the Binary / SOAP formatter?
After many attempts to come up with a solution that worked on all networks
I ended up taking control of serialisation and wrapping each transaction
(in your case object) in an XML-esque tag for ease of parsing at the rx
end. This has the added advantage that any meta information can be added
to this tag if you find that you need it.

Upon each EndRecieve I scan backwards from the end of the rx'ed bytes
looking for ">" if I don't find it I copy the bytes into a new array and
stick it on a queue and go back to BeginRead. If however I do find it then
I check the preceding bytes match </object> (you may have to peek the
previous buffer on the queue if you have received a very few) should it
transpire that the end has been reached dequeue all the buffered buffers
(!) into a memorystream, than add the last buffer and raise your event.
Note also that I used a ThreadPool thread to raise this event so that I
could get back to BeginRecieve ASAP rather than waiting for a potentially
long running event handler to complete.

HTH

"John Hoffman" <John Ho*****@discussions.microsoft.com> wrote in message
news:BC**********************************@microsof t.com...
Hello, I've got a client server app that passes C# objects back and forth
using TCP/IP Async Sockets and Serialization. Works great in the lab, but
when I try it on a the internet or through a slower dial-up, the receive
callback is not always receiving what I wrote. Analyzing this I see that
there is not always a one to one send data/receive data situation. The
data
seems to come over but comes over in multiple receive callbacks. Since I
am
passing C# objects, when I go to deserialize them, they error out.
(usually
with a end of stream error).

The question is, how do I get the BeginReceive to only callback when all
of
the data is there and not chunk it up?? I would hate to have to gooberize
the
code to detect short packets and paste them together on the other end.

TIA, John Hoffman



Jul 21 '05 #4

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

Similar topics

2
by: unluturm | last post by:
Does anyone know how to send structure type data over tcp/ip using .net sockets? I have this vb.net app (client) and a server (C type app). I can send strings but it does not want to parse a...
3
by: John Hoffman | last post by:
Hello, I've got a client server app that passes C# objects back and forth using TCP/IP Async Sockets and Serialization. Works great in the lab, but when I try it on a the internet or through a...
5
by: Arun Kumar | last post by:
Hi In .NET 2.0 I am trying to send a datarow or a data struct through sockets to all connected clients. for example heres the data struct struct { string seqno double SysTime string...
14
by: eliss.carmine | last post by:
I'm using TCP/IP to send a Bitmap object over Sockets. This is my first time using C# at all so I don't know if this is the "right" way to do it. I've already found out several times the way I was...
3
by: prognoob | last post by:
I need help coding a file transfer in C#. It would be over TCP/IP using sockets... most of the solutions i have come across, they use networkstream and i have read online that there is no need to...
4
by: Chandra | last post by:
Hi all, I have a doubt. If I have 2 structures and one is parent of other , ie the child structure is present in the parent one . And if the child structure is declared as dynamic array in the...
1
by: kikisan | last post by:
I am developing a windows service which utilizes the following classes: interface IPersistable; abstract class PersistableObject : IPersistable;
2
by: mkvenkit.vc | last post by:
Hello, I hope this is the right place to post a question on Boost. If not, please let me know where I can post this message and I will do so. I am having a strange problem with std::string as...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.