Whilst working on my engine I noticed something a little odd.
For data transferring I am using TCP. About 60-times a second the client will send a packet containing it’s positional information to the server, and 60 times a second the server sends out positional packets of all entities in the world to all clients.
I know, 60 times a second is overkill! I will reduce this later on (unless it is what’s causing the problem).
After anywhere from 10 - 20 seconds my client seems to lock up when it tries to send data to the server. Here is the send method:
/**
* This method writes a packet of data to a socket.
* @param packet
*/
public void send(Packet packet) {
if (closed)
return;
if (!socket.isConnected()) {
close();
return;
}
try{
byte[] ba = packet.buffer.getOutgoing();
out.write(ba.length & 0xFF);
out.write(ba.length >> 8 & 0xFF);
out.write(ba);
out.flush();
bytesSent += ba.length + 2;
}catch(Exception e) {
close();
}
}
What’s odd, is that this ONLY happens when I run both the client and server application on my desktop computer. If I connect to my server computer from the client, this does not happen.
Any ideas? o: