Key knowledge (to create a web server and TCP) to resolve (a)
1. Create a simple TCP server processes ?
Socket Socket Create -> Binding Ip address and port number -> Set up listeners listen-> Accept Connection Request Wait -> Receive Data -> transmit data -> closed sleeve bytes
Client: create socket -> Request Connection -> accept and process data -> transmit data -> Close the socket
2. Talk about ⼯ the socket send and recv for the principle.
Socket socket, is the way of inter-process communication network, there are tcp and udp two protocols
The socket is to send and receive data by calling two functions send and recv
However, the function does not send the data directly to the web server, wants to send data to the web server, the application must call the operating system interface, data is sent by the operating system through the network card, and send only send data to the transmit buffer (memory the eleven space), and then call the operating system interface by the application, send the card data is controlled by the operating system.
Of course, recv is not available directly from the web server data directly, in order to receive the data sent by the server through the network card must, that is, the operating system receives data through the network card and sends the data to the receive buffer, then the application by socket socket from the receive buffer to accept data in to the application.
3. talk about what is the difference between UDP and TCP?
TCP : connection-oriented: connection requires three-way handshake to disconnect data transmission requires four waving, UDP : the need to connect, send data directly, no matter if it was received TCP : safe - reliable, the data will be retransmission timeout, error checking, flow control and congestion control, to ensure data security, and UDP : does not guarantee the accuracy of the data TCP : connection-oriented, need more resources, more slowly, while the UDP without connecting, fast, available to broadcast
3.1 three-way handshake analysis, why it must be three times instead of twice, four times what?
3.2 Why establish a connection is disconnected three times and is four times?
Because when you create a connection, the client sends a request to establish a client to server connection SYN packet, when the server receives the request, SYN and services will be sent by the client end its ACK in a packet, please accept client (client) once sent in the past.
When disconnected, when the server receives a client request to disconnect FIN packets, it does not bring the FIN ACK request and on their own to send the same message, because it is possible the client's own needs or are this client data transmission can not be disconnected from this client immediately, so FIN packets and ACK packets are sent separately this time, it is disconnected from the required four times.