Apr-13-2019, 02:40 PM
I was watching a tutorial on using socket to create servers and connect clients to make a multiplayer game. The problem is I keep getting this error. It's not an error from python, it's print from socket.error at "Network.py" on line 25. Also I only get the error when I have lines 29 and 28 in Network.py. Thx in advance.
Network.py
server.py
Network.py output
Network.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
import socket class Network(): def __init__( self ): self .client = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self .server = '192.168.1.96' 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' )) |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
import socket from _thread import * import sys server = '192.168.1.96' 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() print ( 'Waiting for connection, Server Started' ) def threaded_client(conn): conn.send( str .encode( 'Connected' )) reply = '' while True : try : data = conn.recieve( 2048 ) reply = data.decode( 'utf-8' ) if notdata: print ( 'Disconnected' ) break else : print ( 'Received: ' , reply) pritn( '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,)) |
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
server.py outputOutput:Waiting for connection, Server Started
Connected to: ('192.168.1.96', 53737)
Lost Connection