HP Rp7410 BSD Sockets Interface Programmer's Guide - Page 39
When to Accept a Connection
View all HP Rp7410 manuals
Add to My Manuals
Save this manual to your list of manuals |
Page 39 highlights
Using Internet Stream Sockets Writing the Server Process Parameter Contents ls addr socket descriptor of local socket socket address addrlen length of address INPUT Value socket descriptor of server socket pointer to address structure where address will be put pointer to the size of struct sockaddr_in OUTPUT Value unchanged pointer to socket address of client socket that server's new socket is connected to pointer to the actual length of address returned in addr Function result: socket descriptor of new socket if accept is successful, -1 if failure occurs. Example: struct sockaddr_in peeraddr; ... addrlen = sizeof(sockaddr_in); s = accept (ls, &peeraddr, &addrlen); There is no way for the server process to indicate which requests it can accept. It must accept all requests or none. Your server process can keep track of which process a connection request is from by examining the address returned by accept. Once you have this address, you can use gethostbyaddr to get the hostname. You can close down the connection if you do not want the server process to communicate with that particular client host or port. When to Accept a Connection The server process should accept a connection after executing the listen call. Refer to the accept(2) man page for more information on accept. Chapter 2 39