ConnectionResetError: [Errno 54] Connection reset by peer

Copyright Notice: Welcome to reprint, but please indicate the source and author of the article. https://blog.csdn.net/handsomehuo/article/details/90900708

Symptoms: ConnectionResetError: [Errno 54] Connection reset by peer

Problem description: The problem encountered during the author socket programming

Problem Cause: parameters for server-side and client-side lack of awareness.

passed to the client side server side, since the client terminal addr is fixed, and therefore whether or send the recv, only s.send () s.recv () like.

But for the server side, there are two types of parameters, the format is:

<socket.socket fd=4, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=0, laddr=('127.0.0.1', 9999), raddr=('127.0.0.1', 49362)> ('127.0.0.1', 49362)

 So when the actual operation to distinguish between:

sock, addr = s.accept()

Receive and send required sock.send () and sock.recv (), rather than s.send () and s.recv ().

Deep-seated logic there is:

  1. socket module encapsulates the TCP / IP protocols, the application layer to facilitate programming.
  2. socket server side is responsible for receiving, get in touch with the client-side by TCP3 handshake.
  3. our sock socket on the client side of the server-side socket is actually the same mechanism, and thus can send another resv
  4. end of the listen socket server many sock, and for different client communications.

 

Guess you like

Origin blog.csdn.net/handsomehuo/article/details/90900708