Lost connection to server error

Hi All,

When I play a game (any module) I continuously get a “connection to server” error after several minutes. A workaround is chatting or moving piece on the map to keep the session alive.

Searching this forum I see post from 2014 stating the same issue.

Is this problem ever effectively been addressed?

Thus spake JohnStaal:

Hi All,

When I play a game (any module) I continuously get a “connection to
server” error after several minutes. A workaround is chatting or moving
piece on the map to keep the session alive.

Searching this forum I see post from 2014 stating the same issue.

Is this problem ever effectively been addressed?

No, as we’ve never been able to reproduce it ourselves. My suspicion is
that it’s a connectivity problem, not a problem with the VASSAL client
or server.


J.

I used to get this constantly. I don’t know what was happening on the server, but it appeared as if it was queuing up messages instead of sending them after the client had been idle for a while. I noticed I was able to force an update by toggling the LFG or away status, or typing something (which was annoying for the game).

So I added a fake keepalive to fix it, and haven’t had it happen since. In SocketNodeClient, I keep track of the last time a message was sent or received, and have a timer task periodically check whether the connection has been idle for 60 seconds. If it has, I send an empty string message, which is enough to stop the issue.

Thus spake Malnorma:

I used to get this constantly. I don’t know what was happening on the
server, but it appeared as if it was queuing up messages instead of
sending them after the client had been idle for a while. I noticed I
was able to force an update by toggling the LFG or away status, or
typing something (which was annoying for the game).

So I added a fake keepalive to fix it, and haven’t had it happen since.
In SocketNodeClient, I keep track of the last time a message was sent or
received, and have a timer task periodically check whether the
connection has been idle for 60 seconds. If it has, I send an empty
string message, which is enough to stop the issue.

Would you mind creating a branch with the modified code, or posting
a patch so I could have a look?


J.

I can do that, but it’s not exactly a good fix… I’m sure there’s a better way to update both the server and client together (TCP keep-alives maybe).
pastebin.com/mkPSZP6q

What was it that was in this paste? I’m rounding up patches now, but the paste is gone.

I’m getting this kind of error, too.

I’ve no idea where to find the SocketNodeClient; nor how to get it to check.

Can someone document this better, so that we can play some good games without having to constantly restart them and dl the current state?

I also have this problem of timing out after being idle for 5 minutes or so, and it started happening when I changed ISP.
Clearly it is a connectivity problem, but a fix would be great.

I’m getting this kind of error, too.

My apologies, I uploaded the paste and figured it was done. The primary game I played on Vassal turned to junk with a new edition and I stopped playing, so I deleted a lot of files to save space on my SSD and figured the work on v4 would be started soon.

As a result, I can’t give you the exact code I was using… but it was literally just sending an empty string as the command, using a timer that was reset every time another packet was sent or received. This way, if the connection was idle for (length of timer), an empty command would be sent, which at least ensured an ACK in response. I’m sure I can re-write that portion if necessary, but it was nothing to write home about.

I was having a similar connection issue, and I have implemented my own version of Malnorma’s workaround as a PR. See github.com/uckelman/vassal/pull/2.

There probably is a better way to do this, but this works for me.
Hope this solves the problem for anyone who stumbles upon this in the future.

For completeness:

diff --git a/src/VASSAL/chat/node/SocketNodeClient.java b/src/VASSAL/chat/node/SocketNodeClient.java
index 84a38f48..bbfca413 100644
--- a/src/VASSAL/chat/node/SocketNodeClient.java
+++ b/src/VASSAL/chat/node/SocketNodeClient.java
@@ -21,6 +21,8 @@ import java.io.IOException;
 import java.net.Socket;
 import java.net.UnknownHostException;
 import java.util.Properties;
+import java.util.Timer;
+import java.util.TimerTask;
 
 import VASSAL.chat.CgiServerStatus;
 import VASSAL.chat.WelcomeMessageServer;
@@ -62,6 +64,17 @@ public class SocketNodeClient extends NodeClient implements SocketWatcher {
     sender = new BufferedSocketHandler(s, this);
     sender.start();
 
+    Timer timer = new Timer();
+
+    timer.scheduleAtFixedRate(new TimerTask() {
+           @Override
+           public void run() {
+               sender.writeLine("");
+           }
+       },
+       2*60*1000,
+       2*60*1000);
+
   }
 
   protected void closeConnection() {

Greetings. This looks like what I need to stop the frequent disconnections with Vassal server. But, how do I use that java script/program/applet? I’ve never learned java. The last time I did some (real) programming was machine code stuff for the precurser of the 8086 cpu. Yep, I’m not young. :smiley:

Thus I would greatly appreciate a ‘how to use’ advice.

Thus spake rjh:

I was having a similar connection issue, and I have implemented my own
version of Malnorma’s workaround as a PR. See
github.com/uckelman/vassal/pull/2.

I’m looking at this presently, as Bug 12825.

This is probably ok. I can’t honeslty see a better way at the moment.*
I guess nearly everything which maintains long-running socket connections
sends server-client level pings to keep connections from dying.

*The one thing we could do to limit unnecessary keep-alive traffic is to
schedule each ping to the server to be two minutes after the most recent
message sent out, rather than simply every two minutes, as there’s not
much point in sending out a ping immediately after some other message
went out—but that’s a bit more fiddly.

I’ll see about getting this into a test build in the morning.


J.

Please try 3.3.0-svn9451-connection_test, available here:

vassalengine.org/~uckelman/tmp/

The suggested patch was a bit heavy-handed, in that there was no way to stop the timer when the connection closed, and also that a keep-alive was being sent ever two minutes regardless of when the last message was sent out.

Outgoing messages are fed by a queue, which can have a timeout set. What I’ve done is set the timeout to two minutes and then send a keep-alive only on a timeout—this way, we should never go more than two minutes without any traffic, but we won’t send extra keep-alives when there’s traffic with content.

You’re good. Thanks.