The client and server programs both have two buffers, the upload buffer and the download buffer, both are 64kb in size (I am talking about application buffers here).
The download buffer is used for downloading available bytes on the network stream at the start of every game tick.
The upload buffer is used for sending all messages (within that game tick) at the end of every game tick.
Current problems I am experiencing is how to handle this all:
- Currently the download buffer can easily overflow, if available bytes available on the stream are greater than the byte buffer (64kb) minus the current data stored in the byte buffer (due to possibly previous half messages received in previous ticks) then the buffer obviously overflows.
- Another problem I have is the upload buffer, throughout a game tick messages are added to the upload buffer; which is then sent at the end of the game tick. If massive messages are sent within one game tick (greater than 64kb) then the upload buffer overflows.
Right now whenever I try sending even one chunk (containing tile data) from the server -> client the upload buffer overflows on the server and the download buffer would overflow on the client. I solved the problem by forcefully making the server send the upload buffer multiple times before the end of a game tick and making the client download the chunk over more than 1 tick (by checking if the buffer is close to overflowing when reading 256 byte increments from the stream during a tick). But I feel like I hackishly solved the problem and my code is no longer consistent.
All replies are appreciated, thanks.
Edit: I would read available bytes from the stream instantaneously as they arrive/are sent but each client is not assigned a thread. Also: sorry if I am asking too much
Edited by Xanather, 17 October 2012 - 03:09 AM.