In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >
Share
Shulou(Shulou.com)06/01 Report--
I. UDP protocol
The characteristics of UDP protocol: user packet protocol
1. UDP protocol is connectionless. That is, there is no need to establish a connection before the data is sent (of course, there is no link release at the end of the data transmission), thus reducing the overhead and the delay before the data is sent.
2. UDP uses best-effort delivery, but does not guarantee reliable delivery, so the host does not need to maintain a complex link state table. (the reliability on the Internet is based on the response, which does not provide reliable payment, that is, no response is required, so there is no need to maintain the status table.)
3. UDP is message-oriented. The sender's UDP does not merge or split the messages delivered by the application process, but retains the boundaries of these messages. That is to say, UDP sends messages one at a time as long as the application layer delivers them to UDP. At the same time, at the receiver, the UDP user Datagram submitted by the IP layer is delivered intact to the application process of the application layer after the header is removed. In other words, UDP delivers one complete message at a time. Therefore, the size of the message must be appropriate, and responsibility will reduce the efficiency of data transmission. If the message is too long, the packet needs to be segmented in the IP layer, which will reduce the efficiency of the IP layer. On the other hand, if the message is too short, after UDP gives it to the IP layer, the header of the IP Datagram will be relatively long, which will also reduce the efficiency of the IP layer.
4. UDP has no congestion control.
Second, the general flow of socket programming based on UDP
1.server end
a. Obtain a valid IP address and port number (port) (the server side needs an agreed port number and IP to facilitate customers to directly establish a connection with the port under the IP)
b. Convert IP and port to a common network format
c. Declare the listener file descriptor (int listen_sock) and "register" the file descriptor as
Socket file (listen_sock=socket (AF_INET,SOCK_DGRAM,0))
Parameters:
AF_INET:IPv4 socket type (description address type format)
SOCK_DGRAM:UDP protocol type (provides connectionless best-effort delivery)
0: indicates that the socket supports only one protocol
d. Bind the corresponding information (IP,port) to listen_sock, because the socket socket is handled by the kernel, so we cannot operate directly. Writing information requires the following actions:
1 > declare the struct sockaddr_in structure and assign the dependent information to the corresponding unit of the structure.
Local.sin_family=AF_INET
Local.sin_port=htons (port)
Local.sin_addr.s_addr=ip
2 > call the bind (int sockfd,struct sockaddr* addr,socklen_t addrlen) function to write ip,port information into (that is, bound) the socket's
f. Use recvfrom () to receive data.
Server side code example:
# include # include void usage (char* arg) {printf ("Missing Parameters:% s [remote ip:] [remote port:]", arg);} int main (int argc,char* argv []) {if (argccargo 3) {usage (argv [0]); exit (1) } in_addr_t _ ip=inet_addr (argv [1]); int _ port=atoi (argv [2]); int sock=socket (AF_INET,SOCK_DGRAM,0); struct sockaddr_in server; socklen_t len=sizeof (server); server.sin_family=AF_INET; server.sin_port=_port; server.sin_addr.s_addr=_ip If (bind (sock, (struct sockaddr*) & server,len)
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.