Skip to content

Instantly share code, notes, and snippets.

@KorbenC
Created September 29, 2013 10:44
Show Gist options
  • Select an option

  • Save KorbenC/6751381 to your computer and use it in GitHub Desktop.

Select an option

Save KorbenC/6751381 to your computer and use it in GitHub Desktop.
Test a connection
#!/usr/bin/env python
import socket
import time
HOST=""
PORT=""
TIMEOUT=1.0
while True:
try:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.settimeout(TIMEOUT)
s.connect((HOST, PORT))
print "[%s] Connection established" % time.strftime("%H:%M:%S")
time.sleep(1)
s.close()
except:
print "[%s] Cannot connect" % time.strftime("%H:%M:%S")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment