数据库

Linux Accept函数简单介绍

时间:2010-12-5 17:23:32  作者:系统运维   来源:域名  查看:  评论:0
内容摘要:复制#include<string.h> #include<sys/socket.h> #include<sys/types.

Linux Accept函数简单介绍
复制#include<string.h> #include<sys/socket.h> #include<sys/types.h> #defineMYPORT3490/*用户接入端口*/   #defineBACKLOG10/*多少等待连接控制*/   main()   {   intsockfd,数简绍new_fd;/*listenonsock_fd,newconnectiononnew_fd*/   structsockaddr_inmy_addr;/*地址信息*/   structsockaddr_intheir_addr;/*connector saddressinformation*/   intsin_size;   sockfd=socket(AF_INET,SOCK_STREAM,0);/*错误检查*/   my_addr.sin_family=AF_INET;/*hostbyteorder*/   my_addr.sin_port=htons(MYPORT);/*short,networkbyteorder*/   my_addr.sin_addr.s_addr=INADDR_ANY;/*auto-fillwithmyIP*/   bzero(&(my_addr.sin_zero),;/*zerotherestofthestruct*/   /*don tforgetyourerrorcheckingforthesecalls:*/   bind(sockfd,(structsockaddr*)&my_addr,sizeof(structsockaddr));   listen(sockfd,BACKLOG);   sin_size=sizeof(structsockaddr_in);   new_fd=accept(sockfd,&their_addr,&sin_size);   .   .   .   1.2.3.4.5.6.7.8.9.10.11.12.13.14.15.16.17.18.19.20.21.22.23.24.
copyright © 2025 powered by 编程之道  滇ICP备2023006006号-34sitemap