Annotations:
Close and shutdown--end data transfer of the socket: close-----Close the socket ID of this process, but the link is still open, other processes with this socket ID can also use this link to read or write the socket ID shutdown--the socket link, read the time may be detective to the EOF Terminator, when writing may receive a sigpipe signal, this signal may not be received until the socket buffer is filled, shutdown also has a closed mode parameter, 0 Can not read, 1 can no longer write, 2 read and write can not. Multi-process applications:
1. If multiple processes share a socket, close is called once, and the count is reduced by 1 until the count is 0 o'clock, which means that the used process calls close and the socket is freed.
2. In a multi-process process, if a process is shutdown (SFD, shut_rdwr), other processes will not be able to communicate. If a process close (SFD) will not affect other processes.
TCP Service side:
1 Create socket, bind socket to local IP with Port # socket.socket (Socket.af_inet,socket. SOCK_STREAM), S.bind ()
2 Start listening for connection #s. Listen ()
3 Enter the loop and continuously accept the client's connection request #s. Accept ()
4 then receive the incoming data, and send the data #s. recv (), S.sendall ()
5 When the transfer is complete, close the socket #s. Close ()
TCP Client:
1 Create socket, connect to remote address # Socket.socket (socket.af_inet,socket. SOCK_STREAM), S.connect ()
2 Send data and receive data after connection # S.sendall (), S.RECV ()
3 When the transfer is complete, close the socket #s. Close ()
Python Socket Learning Tour (ii)