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