The socket server throws an exception when receiving the socket client
Connectionabortederror: [Winerror 10053] The software in your console aborted an established connection.
Socket service-side code
#-*-coding:utf-8-*-#Author:jiang Zu XingImportSocket,timesocketserver=Socket.socket () host="0.0.0.0"Port=9999Socketserver.bind ((host,port)) Socketserver.listen (5) whiletrue:client,addr=socketserver.accept ()Print("connections from:", addr) msg="Show server return data" whileTrue:Print("ready to receive data") Data= CLIENT.RECV (1024) Print("Receive data complete") ifdata = =0:Print("No Data") Break Else: Print(Data.decode ('Utf-8')) Client.send (Msg.encode ()) Client.close () socketserver.close ()
Socket client Code
#-*-coding:utf-8-*-#Author:jiang Zu XingImportsocket,timesocket_client=Socket.socket () host="192.168.1.35"Port=9999Data="222"Socket_client.connect ((host,port))Print("Start Sending") Socket_client.send (Data.encode ())Print("start receiving") msg=SOCKET_CLIENT.RECV (1024)Print("Receive End")Print(Msg.decode ('Utf-8')) Time.sleep (100)
Abnormal
Traceback (most recent): File "c:/users/administrator/desktop/jiang/python/demo/Network programming/socket_server.py ", line, <module> data = CLIENT.RECV (1024x768) Connectionabortederror: [Winerror 10053] The software in your console aborted an established connection.
A problem occurred:
Just learned the socket writing the hands and feet of this
When server-side receive data is turned off, the client is forced to close the connection and the above error message appears.
Suggestions:
Exit the dead loop after receiving the data, do not let the recv () function block, before shutting down the client (file sender), it is recommended to send a message to the server side (file receiver) "I want to disconnect", and then both sides closed the connection close
Connectionabortederror: [Winerror 10053] The software in your console aborted an established connection