473,238 Members | 3,499 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,238 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 1907
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: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
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: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
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...

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.