Winsock Study notes (1)

Source: Internet
Author: User
Tags socket

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;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.