0

I am running a Graphite server to monitor instruments at remote locations. I have a "perpetual" ssh tunnel to the machines from my server (loving autossh) to map their local ports to my server's local port. This works well, data comes through with no hasstles. However we use a flaky satellite connection to the sites, which goes down rather regularly. I am running a "data crawler" on the instrument that is running python and using socket to send packets to the Graphite server. The problem is, if the link goes down temporarily (or the server gets rebooted, for testing mostly), I cannot re-establish the connection to the server. I trap the error, and then run socket.close(), and then re-open, but I just can't re-establish the connection. If I quit the python program and restart it, the connection comes up just fine. Any ideas how I can "refresh" my socket connection?

10k3y3
  • 1
  • 2
  • could you show some code? otherwise any answer would be unprecise (use 4 spaces at new lines to format the code) – User Jun 25 '12 at 14:44
  • maybe try `socket.settimeout(seconds)` for more time tollerance – User Jun 25 '12 at 14:47

1 Answers1

0

It's hard to answer this correctly without a code sample. However, it sounds like you might be trying to reuse a closed socket, which is not possible.

If the socket has been closed (or has experienced an error), you must re-create a new connection using a new socket object. For this to work, the remote server must be able to handle multiple client connections in its accept() loop.

gabrtv
  • 3,558
  • 2
  • 23
  • 28
  • I think this is exactly the problem I am having. Thanks for the insight. I've tried to delete the variable and recreate it, as well as setting the object to None, and then doing a new socket.socket(), but the interpreter then refuses to connect to the server, it even refuses to connect initially (before it even gets close to that piece of the code). – 10k3y3 Jun 28 '12 at 07:09
  • It's possible that your accept() loop on the server cannot handle multiple concurrent connections. If you want to provide some code samples of the relevant server and client bits I might be able to help you fix it. – gabrtv Jun 28 '12 at 22:36