server.py
from socket import *
tcpSerSock = socket(AF_INET,SOCK_STREAM)
tcpSerSock.bind(('127.0.0.1',20000))
tcpSerSock.listen(5)
tcpCliSock, addr = tcpSerSock.accept()
while True:
data = str(input('>'))
tcpCliSock.send(data.encode())
if not data:
break
tcpCliSock.close()
client.py
from socket import *
import fcntl
import os
import time
s = socket(AF_INET, SOCK_STREAM)
s.connect(('127.0.0.1',20000))
fcntl.fcntl(s, fcntl.F_SETFL, os.O_NONBLOCK)
i = 0
while True:
try:
print(s.recv(1024).decode())
except error as e:
i+=1
time.sleep(1)
print(i)