Socket (socket)
First look at the definition:typedef unsigned int u_int;
typedef u_int SOCKET;
Socket is equivalent to the network communication at both ends of the socket, as long as the other side of the socket and their sockets have a communication connection, both sides can send and receive data. The definition is similar to a file handle.
There are five different types of sockets:
1, streaming socket (stream socket)
Defined:
#define SOCK_STREAM 1
Streaming sockets provide bidirectional, sequential, repeatable, and undocumented data flow services that are suitable for handling large amounts of data. It is a connection-oriented, must establish data transmission link, but also must verify the data transmitted to ensure the accuracy of the data. Therefore, the system overhead is large.
2, datagram socket (datagram socket)
Defined:
#define SOCK_DGRAM 2
Datagram sockets also support bidirectional data flow, but do not guarantee the accuracy of the transmitted data, but retain the record boundaries. Because the datagram socket is not joined, such as a join at broadcast time, there is no guarantee that the receiving end is listening. Datagram socket transmission efficiency is high.
3. Original socket (Raw-protocol interface)
Defined:
#define SOCK_RAW 3
The original socket holds the full IP header in the packet, and the previous two sockets receive only user data. Therefore, the data can be analyzed by the original socket.
The other two kinds of sockets are not commonly used, here is not introduced.
The files required for socket development (take Winsock V2.0 as an example):
Header file: Winsock2.h
Library files: ws2_32.lib
Dynamic Library: W32_32.dll
A number of important definitions
1, the basic definition of data type: This everyone can understand.
typedef unsigned char u_char;
typedef unsigned short u_short;
typedef unsigned int u_int;
typedef unsigned long u_long;