Sign in to follow this  
smacker

readbuffer backup

Recommended Posts

smacker    122
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

Share this post


Link to post
Share on other sites
smacker    122
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]

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