readbuffer backup

Started by
1 comment, last by smacker 18 years, 4 months ago
Im using sockets, and C# and was wondering what ways others stoped the read buffer from backing up, and how others seperated packets, I am having problems with packet loss, and packets geting mixed together any help would be great and im not using the TCPClient or TCPServer just sockets, also im using asynchronous sockets to send and recive data thanks
Advertisement
To stop the read buffer from backing up, you have to service requests as fast as they come in, or faster.

To avoid mixing packets up, see the Forum FAQ in the section about packetizing messages over TCP.
enum Bool { True, False, FileNotFound };
in my recive end I first check to see of the bytes read are greater then 1 if not then I return, after that I decode the packet and pull the string from it, to prevent my readbuffer from backing up I load each string into a hashtable, then process the first string im my hashtable, is this a good idea or is there a way to speed up the processing of data?
as for the mixing of packets my send function looks like this
Byte[] databyte = System.Text.Encoding.ASCII.GetBytes(Data);client.BeginSend(databyte,0,databyte.Length,SocketFlags.None, new AsyncCallback(SendBegin), client);private void SendBegin(IAsyncResult ar)		{			Socket Remote = (Socket)ar.AsyncState;			int sent = Remote.EndSend(ar);			lock (Remote.BeginReceive(				readBuffer,0,READ_BUFFER_SIZE,SocketFlags.None,				new AsyncCallback(StreamReceiver),Remote))				  Remote.BeginReceive(				readBuffer,0,READ_BUFFER_SIZE,SocketFlags.None,				new AsyncCallback(StreamReceiver),Remote);		}


now if im sending the lenght of the data how do I read and match up that lenght on the recive end?



Edit: made the post not quite so wide.

[Edited by - hplus0603 on December 5, 2005 1:09:58 PM]

This topic is closed to new replies.

Advertisement