Created
September 8, 2021 11:33
-
-
Save mustafakirimli/d8933435b90315fb8bc44281af5965b6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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