After making the server socket Roughly how to make a socket corresponding to the connected client socket.
Create a TCP socket and fix it with host and ip
example
s_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s_socket.bind((socket.gethostname(), 80))
serversocket.listen(5)
It does not send or receive data. Corresponding to the connected client socket, Create a client socket to handle on the server side.
example
while True:
(clientsocket, address) = serversocket.accept()
ct = client_thread(clientsocket)
ct.run()
Create a client socket for the connected socket. Keep doing this earnestly. The socket created above speaks on its own and automatically allocates ports.
Also, the client socket on the user side and the client socket on the server side are the same type.
The above, how to handle the client socket in the server and how to handle send or recv are separate.
Recommended Posts