Small Knowledge Points:
Socket: An interface between the application layer and the transport layer, one endpoint of the communication. Divided into streaming sockets (providing bidirectional ordered without duplication, no boundary record of the data stream)
and datagram Sockets (bidirectional, not guaranteed to be reliable and orderly and without duplication).
Port: integer identifier, 16 bit, 0~65535,1024 below is reserved bit, such as 80 is HTTP port, 21 is FTP communication port. 1024~49151 for use by general applications. 49152~65535 is a dynamic or private port.
IP: Internet Protocol
TCP/IP Model:
Application layer: (HTTP,FTP,TELNET,DNS,SMTP,POP3, etc.), corresponding to the three layers of the OSI model (application layer, presentation layer, Session layer)
Transport Layer: (TCP, UDP)
Network layer: (ip[Internetwork Protocol],icmp[Internet Message Control Protocol],igmp[internet Group Management Protocol])
Network interface layer (data link layer): Low two layer (data link layer and physical layer) corresponding to the OSI model
Calmly close: One side even closes the connection, but the other side can still read the data from the network stack. If a connection-oriented protocol does not support quiet shutdown, the connection is immediately interrupted and data is lost, as long as one side shuts down the communication, and the receiver cannot read the data. For TCP, the connection can be completely disconnected only if both sides of the connection perform one shutdown. socket programming based on TCP (connection-oriented)
TCP is a connection-oriented, reliable transport protocol
server-side programs:
1: Create socket (socket)
2: Bind the socket to a native address and port (BIND)
3: Set socket to listening mode, ready to receive customer request (listen)
4: Waiting for the arrival of the customer request, when the request arrives, accept the connection request, return a new socket corresponding to this connection (accept)
5: Communication with the returned socket and client (SEND/RECV)
6: Return, wait for another user's request
7: Close Socket
client program:
1: Create socket (socket)
2: Send a connection request to the server side (connect)
3: Communication with the server (recv/send)
4: Close Socket
socket programming based on UDP (non-connection oriented)
UDP is connectionless, unreliable transport protocol
server-side (receiving-side) programs:
1: Create socket (socket)
2: Bind the socket to a local address and port (BIND)
3: Waiting to receive data (RECVFROM)
4: Close Socket
Client (send-side) program:
1: Create socket (socket)
2: Send data (SendTo)
3: Turn off sockets