Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from threading import Thread
- from time import sleep
- from urllib.request import urlopen
- HOST = urlopen("Sitocontenente l'host").read().decode("utf-8") # The remote host
- PORT = 50007 # The same port as used by the server
- def trasmissione():
- global s, HOST
- s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- try:
- s.connect((HOST, PORT))
- except:
- print("Connessione interrotta. Riconnessione tra 10 secondi.")
- HOST = urlopen("Sitocontenente l'host").read().decode("utf-8") #In case the server IP change address/host
- sleep(10)
- trasmissione()
- t1 = Thread(target=ricezione).start()
- while True:
- sleep(0.3)
- a = input(">>> ")
- a = a.encode("cp1252")
- try:
- s.sendall(a)
- except:
- print("Connessione interrotta. Riconnessione tra 10 secondi.")
- sleep(10)
- trasmissione()
- def ricezione():
- while True:
- try:
- data = s.recv(1024)
- except:
- break
- print(data.decode("cp1252"))
- trasmissione()
- s.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement