• Popular Now

• 12
• 12
• 9
• 10
• 13

This topic is 2930 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

I'm having a problem with my server--using localhost, I can connect to the server successfully. When someone else (or me with a proxy) tries to connect, their client hangs while downloading the level. Using Wireshark, I figured out that in the middle of the level sending, the server just stops sending the data. It also does not send the level finalize packet, or the spawn packet. Here's an abbreviated version of the process() function for a player (I'm using Java).
    public void process() {
try {
sel.selectNow();
while(itr.hasNext())
{
SelectionKey key = (SelectionKey) itr.next();
itr.remove();
{
inputbuf.clear();
inputbuf.flip();
while(inputbuf.remaining() > 0)
{
byte cmd = inputbuf.get();
switch(cmd)
{
case (byte) 0x00:
sendServerInfo();
sendMap(currentMap);
spawnAtMapSpawn(currentMap);
outputbuf.flip();
sc.write(outputbuf);
outputbuf.clear();
sendWelcomeChatMessage();
outputbuf.flip();
sc.write(outputbuf);
outputbuf.clear();
ActionReplicator.sendChatMessage("&2"+name+" joined the game");
isConnected = true;
break;
case (byte) 0x01:
//...
break;
}
writebuf = outputbuf.asReadOnlyBuffer(); //Write any packets that were written to the buffer while processing input
writebuf.flip();
sc.write(writebuf);
outputbuf.clear();
}
}
}
}


sendServerInfo() has a dedicated buffer and sends the data during the function. sendMap() uses its own buffer and sends 1024 bytes of the level file at a time, then the level finalize packet. spawnAtMapSpawn() just puts the data in the output buffer (the same function is used when another player joins the server). After checking for new input, the server sends any packets that are waiting in the output buffer to be sent. After part of the level is received, the next packet shown in Wireshark is the "joined the game" chat packet. Thanks in advance!

Share on other sites
There is a distinct lack of any kind of error handling in there. Not even a catch.

Share on other sites
Have you tried stepping through the code with a debugger, or inserting print statements to see at which point it is hanging?

I'm trying to understand your first sentence. Does this mean that an arbitrary number of clients can connect from localhost without the hanging? If there are no localhost clients, can a remote user connect successfully?

Or are you describing the simplest situation where you are connected at localhost and try connecting a single remote client?

Share on other sites
I left out the catch part:
        catch(Exception e)        {            try {                Server.log("Error handling player: " + e);                e.printStackTrace();                Server.players.remove(this);                ActionReplicator.sendChatMessage("&2" + name + " left the game");                ActionReplicator.sendDespawn(id);                sc.close();            } catch (IOException ex) {            }        }

I realize that the empty catch block is bad coding style, but I'm not sure what to do there (and it's virtually impossible for the sendChatMessage or sendDespawn lines to throw an exception, since if something went wrong with one of the other players, it would definitely be caught by that player's exception handling first, resulting in it being removed from Server.players before the message was sent).

Share on other sites
Quote:
 Original post by rip-offHave you tried stepping through the code with a debugger, or inserting print statements to see at which point it is hanging?I'm trying to understand your first sentence. Does this mean that an arbitrary number of clients can connect from localhost without the hanging? If there are no localhost clients, can a remote user connect successfully?Or are you describing the simplest situation where you are connected at localhost and try connecting a single remote client?

I can connect any number of clients from localhost, but even if there are no other clients at all, a remote user can't connect.

Also, forgot to mention--this is actually a custom server for another game, so I can't debug the client, and the problem has to be my fault.

Share on other sites
If you tcpdump/Wireshark a "good" connection, and compare to your own "bad" connection, what is the difference?
You should at least log/console write some message in the exception handling cases.
Also, when it's stopped, break into the program with the debugger, and see what it's doing. Step through it, examine variables, and see what the call stack is.

Share on other sites
I've figured out that the level is definitely being sent, but not received for some reason.

Could my socket settings be the problem? I picked the ones that sounded the best, but I'm not an expert at TCP.

            socket.setKeepAlive(true);            socket.setTcpNoDelay(true);            socket.setTrafficClass(24);            socket.setReuseAddress(false);            socket.setSoTimeout(100);