Jump to content
  • Advertisement
Sign in to follow this  
smacker

readbuffer backup

This topic is 4582 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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
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.

Share this post


Link to post
Share on other sites
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!