Skip to content

Instantly share code, notes, and snippets.

@mustafakirimli
Created September 8, 2021 11:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mustafakirimli/d8933435b90315fb8bc44281af5965b6 to your computer and use it in GitHub Desktop.
Save mustafakirimli/d8933435b90315fb8bc44281af5965b6 to your computer and use it in GitHub Desktop.
#!/bin/python
import sys
import time
import socket
HOST = '127.0.0.1'
PORT = 2001
while True:
try:
print(f"trying to connect {HOST}:{PORT}")
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.connect((HOST, PORT))
s.settimeout(10)
s.sendall(b'Hello, world')
data = s.recv(1024)
print('Received', repr(data))
except Exception:
print("Unexpected error:", sys.exc_info()[0])
pass
time.sleep(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment