Sign in to follow this  

[.net] Strange Socket issue

Recommended Posts

Woltan    122
Dear Forum, I ran into a strange phenomenon. Maybe you can help me, and if you do, I'd very much appreciate it ;) Here we go: I have a non .net server running, that occasionally sends out TCP packages with a size of roughly 500 Bytes. On the client side (where my problem occurs) I have a System.Windows.Forms.Timer timer, that ticks every 10ms. In that tick I check if something was sent by the server and needs to be processed. I check that with the static function. Everything seems to be working just fine until about 1500 Bytes. From there on my receive buffer is somewhat corrupt. It is not that all data is rubbish, but there are some errors in it. First I was guessing that the MTU has something to do with it but then I changed the tick frequency of the timer from 10 to 20 and the problem was resolved.... until the server sent about 4500 Bytes. From there on the buffer again was corrupt. Here again what happens on the client side in a few source snippets:
//Somewhere before
ConnectionTimer = new Timer();
ConnectionTimer.Tick += new EventHandler(ConnectionTimer_Tick);
ConnectionTimer.Interval = 10;

void Recv()
List<Socket> lTemp = new List<Socket>();
Socket.Select(lTemp, null, null, 5);
Int32 iRecv = TCP.Receive(RecvBuffer);
InterpreteBuffer(RecvBuffer, iRecv);

I hope you can help me with a link, tipp, suggestion,..., anything Regards Woltan

Share this post

Link to post
Share on other sites
SiCrane    11839
TCP is a stream protocol, which means, among other things, that a single receive call will not necessarily retrieve the same data as a single send call from the other side. For example, if the sender sends "Hello" and "world" as two different sends, the receiver could receive "HelloWorld" as a single receive or "Hell", "oWo" and "rld" as three different receive calls. Since your code only contains a single Receive() call, it looks like you don't take this into account.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this