Async TCP Sockets

M

mak

Dear Friends,

I'm working on real time stock quotes display. Using Async tcp sockets
in .net csharp. Client software running perfect on LAN and ISDN but not
good on ip dialup. After lot of testing i found the result is, I'm
sending packet by packet data to client socket but client receiving
stream read all packets at once.

Can i reduce the tcp window size in .net or any method i can use to
bound client get packet by packet data.

Please reply, its urgent I really appreciate.

Thanks,

-mak
 
C

Carlos J. Quintero [.NET MVP]

You can not control the packets sent over the network, think in terms of
streams. So, this is a typical boundary problem of sockets. There are 3
solutions to this problem:

1) Use packets of fixed size
2) Include the (variable) size in each packet
3) Use a delimiter to separate packets

With any of those approaches the receiver will know to separate the messages
from the stream.

Details and samples are provided in the following book:

C# Network Programming
http://www.amazon.com/exec/obidos/tg/detail/-/0782141765/002-3466325-9040812?v=glance

--

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
 
J

just_starting

Hi all,

I am also facing the same problem as stated by Mak, and I have
implemented Carlos's suggestion.

But the problem is the number of bytes received by the asynchronous
socket is not exact multiple of the piecesize as I had anticipated.

For example-
lets assume the piece size is 8000Bytes.
But the listener socket data receives any amount of data from 0 to the
buffer size it is provided with.My buffer size for the testing case
was 33000Bytes.
And the data it received was like-25876 Bytes,26420 Bytes,sometimes
33000bytes.

I am at the end of my wits what is happening here.

Any kind of help will be deeply appreciated.

Thank you all.
 
J

just_starting

Sorry not to mention it in my previous post:

As the number of bytes received is not exact multiple of (piecesize +
delimiter) how am I going to know what the bytes received contains and
what to do with it.

to make it a bit clear what is happening is:

pppp:for a piece, dd for a delimiter, so ppppdd makes one piece.

but what i get at the listener end issomething like ppppddppppddpp or
something like it. So at the end I dont know how to deal with the
fractured pieces at the end and also the fractured piece that will be
received next at the listener.

Thanks.
 
C

Chad Z. Hower aka Kudzu

just_starting said:
But the problem is the number of bytes received by the asynchronous
socket is not exact multiple of the piecesize as I had anticipated.

And it never will be - thats how sockets work, and in fact most network transports.
And the data it received was like-25876 Bytes,26420 Bytes,sometimes
33000bytes.

I am at the end of my wits what is happening here.

You will receive whatever the network happens to see at that time. You have to reassemble it.


--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programming is an art form that fights back"

Develop ASP.NET applications easier and in less time:
http://www.atozed.com/IntraWeb/
 
A

at

It is streaming, dude, the implication is you don't know how much a get
receives. It is your own protocol that makes sense of the stream of bytes so
you need to buffer, determine begin and end and then do whatever you want to
do with it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top