Reading TCP data stream and finding an End of line

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



This may be more theory than code,

I am currently using a 3rd party TCP client socket tool to read in
data from a connection. The tool supports and End of Line(EOL)
character. The problem is that the data that is coming in does not
have an EOL character or set of characters. The first 4 bytes of the
data contain a set of defined characters "ABCD". The next 4 bytes
give the size of the whole packet, "0012". After that, there is a
random length of data.

Of course, the TCP tools DataIn function fires for partial messages,
which I have to assemble in a byte[] buffer, while waiting for the
rest of the message. Well I only have the length of the message to go
on. If I use the starting characters "ABCD" as the EOL, the last
message in will not get processed until another. This is to be
expected. I could count the number of characters until the message
length, copy out the message, but would then have to shift the entire
buffer to the left in case part of another message was in the previous
transmission. Or is there a natural break so that one event can not
have two separate partial TCP packets? I know that this is probably a
3rd party question.

What is a good way to deal with something like this?

Thanks,
Tom

.



Relevant Pages

  • Re: problem reading TCP packets on socket
    ... the client strips down the message in the ... characters on my bufferedReader, and I start over. ... I realized that problems arised when TCP ... Using a BufferedReader as you have done improves the chances of getting a whole array in one read, but still does not ensure it. ...
    (comp.lang.java.programmer)
  • Re: Real terminal + SimH + telnet
    ... and let simh map that to a tcp port? ... I made a file that is 165 blocks in size - I'm assuming this is bigger than the TCP/IP buffers. ... I see these lines but they are corrupted - characters are missing. ...
    (comp.os.vms)
  • Re: Real terminal + SimH + telnet
    ... and let simh map that to a tcp port? ... is bigger than the TCP/IP buffers. ... corrupted - characters are missing. ... The "right" solution is obviously to do telnet do the VMS box without simulating a DZV on the way, and let tcp handle all flow control up to your local machine, and then have flow control between your local machine and the terminal. ...
    (comp.os.vms)
  • problem reading TCP packets on socket
    ... the client strips down the message in the ... characters on my bufferedReader, and I start over. ... I realized that problems arised when TCP ...
    (comp.lang.java.programmer)