Building a TCP library, advice appreciated

Blitz3D Forums/Blitz3D Programming/Building a TCP library, advice appreciated

poopla(Posted 2005) [#1]
Hi all, I've been looking over the TCP command set and it looks pretty straight forward. I was just curious about handling the data coming over an active stream. Seeing as the docs show reading the stream until Eof(StreamHandle) returns true, what's the best method for identifying what data type to poll off it. I was thinking sending a short to flag each segment in the stream would work, but I'm not very knowledgable of networking so here I am.

Any other stuff I should be aware of before diving in?


DH(Posted 2005) [#2]
A few things to keep in mind when dealing with the TCP streams in Blitz.

A. Data keeps coming in! As long as the client keeps sending data, the stream will keep filling. Sending just an int or a Short a few at a time will not arrive as such, it will pile up on the other side. If latency is high, only a bit (if that) will get there in decent time.

Best way to manage this is before sending data over TCP is to send a short indicating how many bytes you will be sending. That way, on the recieving end, you can just monitor the stream for a readavail of >=2. When its >=2 then read in the short. This short tells how many bytes should be coming in. Just keep doing a readavail until it gets to the size your expecting, then read it all out in one chunk into a bank and send the bank for processing.

Another way is to do a 'Cell', where each bit of info you send over the TCP is of a certain size. If you dont have enough data to meet the size, then just fill the remainder with 0's. The advantage to Cell is you can anticipate a certain size of datagram. This way you can just keep streaming data.

The advantage to short (size) first is that you can vary (optimize) the type and amount of data sent to the host (or client).

How is that for ideas?


poopla(Posted 2005) [#3]
Hey DarkHalf, been a while :). What's your MSN we can chat again.


DH(Posted 2005) [#4]
master_prompt<at symbol>hotmail.com