Sockets closes after 15 minutes on inet not on lan

J

Jan Jansen

Hello all,

I'm keeping a socket open for a long time (several hours). When
testing on my local lan network everything works, the socket stays
open for several hours.

When i upload the server and connect a client to the server (over the
internet) everything works fine. But when i don't send any data from
client to server in 15-20 minutes the server closes the socket and the
client receives a:
"Connection reset by peer: socket write error"
when trying to write to the socket.

This does not happen when testing on the local lan.

Is there something different about opening and keeping sockets open on
the internet compared to a local network?

I'm using:
s.setKeepAlive(true);
s.setSoTimeout(0);
To keep the sockets open. In theory this should be enough. On local
network this seems to be enough, but not on the internet.

The server and client are standard java programs. Both run on the
latest 1.4 jdk.

For the last couple of days i've been asking myself why the server
closes the socket after 15-20 minutes. Can somebody offer me a helping
hand?

Thanks,

Jan Jansen
 
R

Rene

Jan Jansen said:
Hello all,

I'm keeping a socket open for a long time (several hours). When
testing on my local lan network everything works, the socket stays
open for several hours.

When i upload the server and connect a client to the server (over the
internet) everything works fine. But when i don't send any data from
client to server in 15-20 minutes the server closes the socket and the
client receives a:
"Connection reset by peer: socket write error"
when trying to write to the socket.

This does not happen when testing on the local lan.

Is there something different about opening and keeping sockets open on
the internet compared to a local network?

No but there might be a NAT device or firewall somewhere between the two
hosts which drops the connection entry after not having seen a packet after
X minutes. Then the next packet is dropped because it is not a SYN
(connection initiation) packet, causing your socket object to give you the
reset message.
I'm using:
s.setKeepAlive(true);
s.setSoTimeout(0);
To keep the sockets open. In theory this should be enough. On local
network this seems to be enough, but not on the internet.

The server and client are standard java programs. Both run on the
latest 1.4 jdk.

For the last couple of days i've been asking myself why the server
closes the socket after 15-20 minutes. Can somebody offer me a helping
hand?

It should be enough, especially when you use keepalives. But to be sure you
will need to grab a network sniffer and watch what exactly gets sent and
when to pinpoint the culprit.

In the worst case, just send otherwise meaningless PING/PONG messages to
the server once a minute after idle or so.

CU

Rene
 
J

Jan Jansen

No but there might be a NAT device or firewall somewhere between the two
hosts which drops the connection entry after not having seen a packet after
X minutes. Then the next packet is dropped because it is not a SYN
(connection initiation) packet, causing your socket object to give you the
reset message.

That's what i thought also, i self have a nat router but i've also
tested with another person which doesn't have a router or firewall,
the connection still got closed by the server. It's a strange thing.
It should be enough, especially when you use keepalives. But to be sure you
will need to grab a network sniffer and watch what exactly gets sent and
when to pinpoint the culprit.

In the worst case, just send otherwise meaningless PING/PONG messages to
the server once a minute after idle or so.

First tests seem to prove that sending a little ping message works in
my case, the connection isn't closed anymore. I guess there is
something on the serverside closing my sockets when they're idle for
15-20 minutes. I'll get in contact with the sysadmin, but when doing
ping with interval of 1 minute everything seems to work fine.

Thanks!


Jan Jansen
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,225
Members
46,815
Latest member
treekmostly22

Latest Threads

Top