In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces what is the fragmentation of the IP layer during UDP transmission, which has a certain reference value and can be used for reference by friends who need it. I hope you will learn a lot after reading this article. Next, let the editor take you to learn about it.
We know that when the network data is transmitted between the application layer programs, at the sending end, the data will be transmitted down the protocol stack from the application layer, through the TCP/IP layer, and then sent through the link layer, while at the receiving end, the data will be received through the link layer, and then transmitted up the protocol stack, through the IP/TCP layer, and finally read by the application layer programs.
First, let's take a look at the program, the server:
# include # include int main () {struct sockaddr_in srvAddr; bzero (& srvAddr,sizeof (srvAddr)); srvAddr.sin_family = AF_INET; srvAddr.sin_addr.s_addr = htonl (INADDR_ANY); srvAddr.sin_port = htons (8765); int srvAddrLen = sizeof (srvAddr); int iSock = socket (AF_INET, SOCK_DGRAM, 0) / udp bind (iSock, (struct sockaddr *) & srvAddr, sizeof (srvAddr)); while (1) {getchar (); char szBuf [50001] = {0}; recvfrom (iSock, szBuf, sizeof (szBuf)-1,0, (struct sockaddr *) & srvAddr, (socklen_t*) & srvAddrLen); printf ("msg from client [% s]\ n", szBuf) } close (iSock); return 0;}
Client:
# include # include int main (int argc, char * argv []) {struct sockaddr_in srvAddr; bzero (& srvAddr, sizeof (srvAddr)); srvAddr.sin_family = AF_INET; srvAddr.sin_addr.s_addr = inet_addr ("10.100.70.140"); srvAddr.sin_port = htons (8765); int iSock = socket (AF_INET, SOCK_DGRAM, 0) / / udp # define N 2000 char szBuf [N] = {0}; for (unsigned int i = 0; I
< N; i++) //字符数组最后一个字符不要求是'\0' { szBuf[i] = 'a'; } int iRet = sendto(iSock, szBuf, sizeof(szBuf), 0, (struct sockaddr *)&srvAddr, sizeof(srvAddr)); printf("send size is %d, iRet is %d, errmsg[%s]\n", sizeof(szBuf), iRet, strerror(errno)); close(iSock); return 0;} 我们在服务端抓包, 结果为: xxxxxx$ sudo tcpdump -iany src host 10.100.70.139 -Xnlps0tcpdump: verbose output suppressed, use -v or -vv for full protocol decodelistening on any, link-type LINUX_SLL (Linux cooked), capture size 65535 bytes00:13:57.187159 IP 10.100.70.139.46671 >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.