In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
Create socket- > named socket- > create listener
4. Accept connection
Code: int accept (int sockfd,struct sockaddr addr,socklen_t addrlen)
4.2 Parameter comment
4.2.1 sockfd: listening socket that has performed Lee stem system call
4.2.2 addr: used to obtain the remote socket address of the accepted connection. The length is the next parameter addlen.
Specify.
4.3 return
A new socket connection was returned successfully, and the socket is the unique identity
Failed to return-1 and set errno
In the case of client disconnection mentioned in the previous article, the supplementary code is now available.
Int main (int argc,char * argv []) {if (argc=0); / / use assertions to create code that is more stable, of better quality, and less error-prone. You can use assertions when you need to interrupt the current operation when a value is FALSE. Unit tests must use Junit/JunitX. Int ret = bind (sock, {struct sockaddr*} & address,sizeof (address)); assert (retinue 1); ret = listen (sock,5); assert (ret! = 1); sleep (20); / / wait 20 seconds for the client connection and related operations to complete struct sockaddr_in client; socklen_t client_addrlength = sizeof (client); int connfd = accept (sock, {struct sockaddr*} & client,&client_addrlength); if (connfd)
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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.