HP Rp7410 BSD Sockets Interface Programmer's Guide - Page 36
Binding a Socket Address to the Server, Process's Socket
View all HP Rp7410 manuals
Add to My Manuals
Save this manual to your list of manuals |
Page 36 highlights
Using Internet Stream Sockets Writing the Server Process When to Create Sockets The server process should create a socket before any other BSD Sockets system calls. Refer to the socket(2) man page for more information on socket. Binding a Socket Address to the Server Process's Socket After your server process has created a socket, it must call bind to bind a socket address. Until an address is bound to the server socket, other processes have no way to reference it. The server process must bind a specific port address to this socket, which is used for listening. Otherwise, a client process would not know what port to connect to for the desired service. Set up the address structure with a local address before you make a bind call. Use a wildcard address so your server process does not have to look up its own internet address. bind and its parameters are described in the following table. Include files: System call: #include #include #include bind (s, addr, addrlen) int s; struct sockaddr *addr; int addrlen; Parameter Description of Contents s addr socket descriptor of local socket socket address addrlen length of socket address INPUT Value socket descriptor of socket to be bound pointer to address to be bound to s size of struct sockaddr_in Function result: 0 if bind is successful, -1 if failure occurs. 36 Chapter 2