Socket Definition
Network Programming in Linux is implemented through the socket interface. The socket is a special I/O interface, which is also a file descriptor. Socket is a common communication mechanism between processes. It not only enables communication between processes on local machines, but also enables communication between processes on different machines through the network.
Each socket is represented by a semi-Related Description {protocol, local address, and port number; A complete socket is represented by a description {protocol, local address, local port, remote address, remote port. Socket also has a function call similar to opening a file. This function returns an integer socket descriptor, and subsequent connection establishment and data transmission operations are implemented through socket.
Socket Type
(1) stream socket
Stream socket (sock_stream ).
Stream sockets provide reliable and connection-oriented communication streams. They use the TCP protocol to ensure the correctness and sequence of data transmission.
(2) datagram socket (sock_dgram)
A datagram socket defines a connectionless service. Data is transmitted through independent packets, which is out of order and is not guaranteed to be reliable and error-free. It uses the datagram protocol (UDP)
(3) original socket
The original socket allows direct access by the underlying protocol, such as IP or ICMP. It is powerful but inconvenient to use and is mainly used for the development of some protocols.
Socket programming (1)