handling packets on recive

how do ppl handle this, Im finding as I move deeper into my project that my readbuffer is backing up, my packets were geting smashed together so I started sending a delimer at the end of each packet and spliting the string to seperate each packet, is there a good way to hold these split packets until I can process them
thanks a ton

btw im using C#



Answer this question

handling packets on recive

  • khandar

    I having a hard time geting this to work right could you point me in the direction of a sample on holding packets into a stringbuffer, whats happening is im sending tons of packets from my server app to my client app and the packets are geting smashed together, so I need to split them and them hold them for prossesing, or find away to prosses them faster.
    thanks

  • Colin F

    If you are workign with a TCP connection, there is no gaurantee that what you send in one call to a sockets send method is what is received in one recieve call on the server.  For example, the client could send 60 bytes in one call to Send ( ...) and the server app could require 3 calls to receive to get all 60 bytes.

    You have it right, the way to handle this is via a delimeter or some kind.  Some methods to do this are:

    - special character in the data stream

    - byte count per "packet"

    - make each "packet" the same size so there is no need for delimeters.

     

     



  • alkaline

    holding packet string into StringBuffer will  be a good idea. Also, process the string delimer using Regular Expression will give you the best optmized performance.


  • m.zirino

    Just replace your string that holds your packets with StringBuffer (In your existing code). Also, when you're trying to process those packet (held in the StringBuffer) use RegulareExpression to make this process (split).

    In this way, i think it'll faster and more feasible.

  • handling packets on recive