Network programming (three)-tcp basic programming

1.ipv4 structure
Insert picture description here
Insert picture description here

2.socket
Insert picture description here
Insert picture description here
Insert picture description here
3.connect
Insert picture description here
4.bind
bind is to bind the ip and port to the socket. The
client may not call bind to bind the port. The kernel will temporarily allocate one, but the server cannot bind the port. If it is not bound Then the client cannot connect to the server.
Insert picture description here
Insert picture description here
5. After
Insert picture description here
Insert picture description here
listening
Insert picture description here
6. accept 7. close
fork, the descriptor opened by the parent process is copied to the child process, so the reference count of these file descriptors is 2. Only the parent and child processes are Close the descriptor, the descriptor will be actually closed

Insert picture description here
8. After the descriptor reference count
fork, the parent and child processes must all close the connected socket, otherwise the socket is not really closed, the descriptor will be exhausted, and the tcp connection will not be terminated
Insert picture description here
Insert picture description here

Guess you like

Origin blog.csdn.net/chengcheng1024/article/details/115246543