Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #TCp client
- import socket
- global ip,port,s
- ip = '93.141.164.3'
- port = 13337
- BUFFER_SIZE = 1024
- MESSAGE = "Hello, World! domicatest"
- s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- s.settimeout(5)
- #s.connect((TCP_IP, TCP_PORT))
- def connect():
- try:
- s.connect((ip, port))
- except Exception as e:
- s.close()
- print("connect exception",e)
- return False
- return True
- def keepconnecting():
- while connect()==False:
- print("Connection error")
- keepconnecting()
- while 1:
- try:
- s.send(MESSAGE.encode())
- data = s.recv(BUFFER_SIZE)
- print ("received data:", data.decode())
- except Exception as e:
- print("Connection error!")
- print(e)
- if "[WinError 10054]" in str(e) or str(e)=="":
- s.close()
- print("I'll try to reconnect")
- keepconnecting()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement