I am currently using the Java implementation of the robust UDP protocol found here . There are absolutely no textbooks in the project, so it was very difficult for me to identify problems.
I installed the client and server. The server runs on localhost: 1234, and the client runs on localhost: 1235. First, the server is installed, and the loops listen on connections -
try { ReliableSocket clientSocket = server.socket.accept(); InetSocketAddress clientAddress = (InetSocketAddress) clientSocket.getRemoteSocketAddress(); Logger.getLogger("ServerConnectionListener").info("New Connection from "+ clientAddress.getHostName()+":"+clientAddress.getPort()+" Processing..."); LessurConnectedClient client = new LessurConnectedClient(clientSocket); ClientCommunicationSocketListener listener = new ClientCommunicationSocketListener(this, client); clientSocket.addListener(listener); } catch (Exception e) { e.printStackTrace(); }
When a connection is established, it creates a listener for events on this socket -
class ClientCommunicationSocketListener implements ReliableSocketListener { ServerConnectionListener connectionListener; LessurConnectedClient client; public ClientCommunicationSocketListener(ServerConnectionListener connectionListener, LessurConnectedClient client){ this.connectionListener = connectionListener; this.client = client; } @Override public void packetReceivedInOrder() { connectionListener.server.handlePacket(client); } @Override public void packetReceivedOutOfOrder() { connectionListener.server.handlePacket(client); } }
When a packet is received, it passes it to the .handlePacket server, which performs the debug print procedure "Received packet!"
My client connects to the server like this -
LessurClient client = new LessurClient(); InetSocketAddress a = (InetSocketAddress) server.getSocket().getLocalSocketAddress(); Logger.getLogger("client-connector").info("Trying to connect to server "+ a.getAddress().toString()+":"+ a.getPort()); client.connect(a.getAddress(), a.getPort()); // LessurClient.connect public void connect(InetAddress address, int port){ try { socket = new ReliableSocket(address, port, InetAddress.getLocalHost(), 1235); isConnected = true; Logger.getLogger("LessurClient").info("Connected to server "+address.getHostAddress()+":"+port); } catch (IOException e) { e.printStackTrace(); } }
I linked my code, so when I press the "Z" key, it will send the packet to the server like this:
public void sendPacket(GamePacket packet){ if(!isConnected){ Logger.getLogger("LessurClient").severe("Can't send packet. Client is not connected to any server."); return; } try { OutputStream o = socket.getOutputStream(); o.write(packet.getData()); o.flush(); Logger.getLogger("LessurClient").info("Sending Packet with data \""+packet.getData()+"\" to server "+socket.getInetAddress().toString()+":"+socket.getPort()); } catch (IOException e) { e.printStackTrace(); } }
My problem is that after sending 32 packets the server no longer receives packets, and after sending 64 packets it fails. I examined the code, and it seems that something is associated with the fact that packets are not removed from the receive queue, as when changing the _recvQueueSize variable in ReliableSocket.java:1815 from 32 to 40, I can now send 40 packets without any mistakes.
Can someone help me identify this issue? I looked at the code all day.