server
import socketserver import time import pickle import threading a = 0 def main(): global a while True: a1 = int(a) digits = str(a1) result = '' while digits: digits, last3 = digits[:-3], digits[-3:] if result: result = (last3 + ',' + result) else: result = last3 file_1 = open("file.txt", "w") file_1.write(str(result)) file_1.close() print(result) time.sleep(0.05) t1 = threading.Thread(target=main) t1.start() class MyTCPServer(socketserver.ThreadingTCPServer): allow_reuse_address = True class MyTCPServerHandler(socketserver.BaseRequestHandler): def handle(self): global a b = pickle.loads(self.request.recv(1024)) a=a+b self.request.sendall(pickle.dumps(a)) server = MyTCPServer(('localhost', 13373), MyTCPServerHandler) server.serve_forever()
client
import time import socket import threading import pickle x = 1 def internet(): global x while True: conn = socket.socket(socket.AF_INET, socket.SOCK_STREAM) conn.connect(("localhost", 13373)) conn.sendall(pickle.dumps(x)) y = pickle.loads(conn.recv(1024)) conn.close() print(y) time.sleep(0.05) t1 = threading.Thread(target=internet) t1.start()