Python Forum
Server and Network (socket) [WinError 10053]
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Server and Network (socket) [WinError 10053]
#1
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 Angry :

[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:
Output:
Connected [WinError 10053] An established connection was aborted by the software in your host machine None [WinError 10053] An established connection was aborted by the software in your host machine None Process finished with exit code 0
server.py output:
Output:
Waiting for connection, Server Started Connected to: ('192.168...', ...) Lost connection
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!
Reply
#2
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)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Paramiko Server -- Exception (server): Error reading SSH protocol banner ujlain 3 4,276 Jul-24-2023, 06:52 AM
Last Post: Gribouillis
  Socket server problem H84Gabor 0 1,207 Jun-21-2022, 12:14 AM
Last Post: H84Gabor
  [WinError 10057] lolloiltizio 0 4,905 Aug-10-2020, 05:57 PM
Last Post: lolloiltizio
  [Socket] Can a server be accessible from devices not in the same network? SheeppOSU 2 2,934 Jun-18-2020, 01:29 PM
Last Post: DeaD_EyE
  Writing socket server NewPy_thwan_Programmer 0 1,915 Feb-23-2020, 03:58 PM
Last Post: NewPy_thwan_Programmer
  Server and Network (socket) [WinError 10053] SheeppOSU 2 22,172 Apr-13-2019, 09:23 PM
Last Post: SheeppOSU
  Async socket server and ports Pengwyn 1 10,707 Feb-28-2019, 12:13 AM
Last Post: DeaD_EyE
  Multi connection socket server help! MuntyScruntfundle 0 2,685 Feb-19-2019, 12:03 PM
Last Post: MuntyScruntfundle
  Multiple network socket servers? MuntyScruntfundle 1 2,470 Nov-13-2018, 03:46 PM
Last Post: wavic
  Send data BMP180 between client and server trought module socket smalhao 0 2,805 Jul-30-2018, 12:56 PM
Last Post: smalhao

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020