Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Unix Network programming udp simple routine

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

server.c#include /* See NOTES */#include #include #include #include #include #include #include int main (int argc, char** argv){int ret;int len = sizeof (struct sockaddr);//create socketint sockfd = socket (AF_INET, SOCK_DGRAM,0);if (sockfd == -1){perror ("socket\n");exit(1);}//bind addr address to socket//initialize address struct sockaddr_in addr;addr.sin_family = AF_INET;addr.sin_port = htons(4444); addr.sin_addr.s_addr = INADDR_ANY;memset (addr.sin_zero,8,0);//bind ret = bind (sockfd, (struct sockaddr*)&addr, len);if (ret == -1){perror ("bind\n");exit(1);}//receive data struct sockaddr_in addr_client;while(1){char buf[100];memset (buf,100,0);socklen_t length = sizeof(struct sockaddr);fputs("wait for data...\ n",stdout);ssize_t recnum = recvfrom(sockfd, buf, 100,MSG_WAITALL, (struct sockaddr*)&addr_client,&length);if(recnum

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.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report