Server and Network (socket) [WinError 10053] - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Networking (https://python-forum.io/forum-12.html) +--- Thread: Server and Network (socket) [WinError 10053] (/thread-19875.html) |
Server and Network (socket) [WinError 10053] - Timxxx - Jul-17-2019 I was watching a tutorial on making a multiplayer game and clients to connect it. The Problem is that I keep getting this error and I don't know why : [WinError 10053] An established connection was aborted by the software in your host machine network.py import socket class Network: def __init__(self): self.client = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.server = "..." self.port = 5555 self.addr = (self.server, self.port) self.id = self.connect() print(self.id) def connect(self): try: self.client.connect(self.addr) return self.client.recv(2048).decode() except: pass def send(self, data): try: self.client.send(str.encode(data)) return self.client.recv(2048).decode() except socket.error as e: print(e) n = Network() print(n.send('Hello')) print(n.send('Working'))server.py import socket from _thread import * import sys server = "..." port = 5555 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) try: s.bind((server, port)) except socket.error as e: str(e) s.listen(2) print("Waiting for connection, Server Started") def threaded_client(conn): conn.send(str.encode("Connected")) reply = "" while True: try: data = conn.receiv(2048) reply = data.decode("utf-8") if not data: print("Disconnected") break else: print("Received: ", reply) print("Sending: ", reply) conn.sendall(str.encode(reply)) except: break print("Lost connection") conn.close() while True: conn, addr = s.accept() print("Connected to:", addr) start_new_thread(threaded_client, (conn,)) network.py output: server.py output: I only get the error when I have the lines 29/30 in network.py.Thanks in Advance! (Note: I removed the IP adresses, etc just because I don't want you to see them. They're present in the real code.) Edit: I just realised that there's a Forum for networking. I'm sorry! RE: Server and Network (socket) [WinError 10053] - iMuny - Aug-23-2019 I've made some modifications to your threaded_client method, the modified method is below def threaded_client(conn): conn.send(str.encode("Connected")) reply = "" while True: try: data = conn.recv(2048) reply = data.decode("utf-8") if data: print("Received: ", reply) print("Sending: ", reply) conn.sendall(str.encode(reply)) except: break print("Lost connection") conn.close()line 24 of server.py should be data = conn.recv(2048) |