How To Make A Socket A Listen-only Connection Endpoint - Listen()
/*Code Sample: Make a Socket a Listen-onlyConnection Endpoint - listen() by GlobalGuideline.com*/#include <sys/types.h>#include <sys/socket.h>int listen(int s, int backlog)/*listen establishes the socket as a passive endpoint of a connection. It does notsuspend process execution.*//*No messages can be sent through this socket.Incoming messages can be received.*//*s is the file descriptor associated with the socket created using the socket() system call. backlog is the size of the queueof waiting requests while the server is busywith a service request. The currentsystem-imposed maximum value is 5.*//*0 is returned on success, -1 on error with errno indicating the problem.*/Example:#include <sys/types.h>#include <sys/socket.h>int sockfd; /* socket file descriptor */if(listen(sockfd, 5) < 0) printf ("listen error %dn", errno);
2009-2016 downloadmela.com. All rights reserved.