In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
/ * *
* function: create sockets and specify protocol and type at the same time
* # include
* family (protocol suite): AF_INET (IPv4 protocol) AF_INET6 (IPv6 protocol)
* type (socket type): SOCK_STREAM (streaming socket) TCP communication usage
SOCK_DGRAM (Datagram socket) UDP communication usage
SOCK_RAW (original socket)
* protocol: this parameter is 0. 0 if the socket type is not the original socket.
* return value: success: non-negative socket file descriptor
Failed:-1
* int socket (int family,int type,int protocol)
, /
/ * *
* function: bind the address information stored in the corresponding address structure to the socket. Mainly server-side sockets need to be bound, client sockets generally do not need to bind, the kernel will automatically assign addresses to sockets
The file descriptor returned successfully by the * sockfd:socket () function
* my_addr: bind the structure that stores address information
* addrelen: the size of the storage address information structure
* returned value: success: 0
Failed:-1
* int bind (int sockfd,struct sockaddr * my_addr,int addrlen)
, /
Struct sockaddr {
Unsigned short sa_family; / / protocol suite AF_XXX
Char sa_data [14]; / / 14-byte protocol address
}
Struct sockaddr_in {
Short int sin_family; / / protocol suite
Unsigned short int sin_port; / / Port number short integer occupies 2 bytes and 16 bits
Struct in_addr sin_addr; / / IP address occupies 4 bytes and 32 bits
Unsigned char sin_zero [8]; / / fill 0, occupy 8 bytes to keep struct sockaddr and struct sockaddr_in structures the same size
}
Struct in_addr {
Unsigned long sprinter addr; / / 32-bit ip address
}
Struct sockaddr_in is usually used to save a network address, and when used, it is forcefully converted to a pointer of type struct sockaddr.
/ * *
* # include
* function: client establishes a connection to the server
* int connect (int sockfd,struct sockaddr * serv_addr,int addrlen)
* returned value: success: 0
Failed:-1
, /
/ * *
* function: set the socket to listen mode (passive mode) and prepare to receive requests from the client.
* backlog: the maximum number of requests allowed in the request queue. The default value for most systems is 5.
* int listen (int sockfd,int backlog)
* returned value: success: 0
Failed:-1
, /
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.