Binding Socket Addresses To Datagram Sockets - HP Rp3440-4 - 9000 - 0 MB RAM Programmer's Manual

Bsd sockets interface programmer’s guide
Hide thumbs Also See for Rp3440-4 - 9000 - 0 MB RAM:
Table of Contents

Advertisement

When to Create Sockets
The server or client 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 Socket Addresses to Datagram
Sockets
After each process has created a socket, it must call bind to bind a
socket address. Until an address is bound, other processes have no way
to reference it.
The server process must bind a specific port address to its socket.
Otherwise, a client process would not know what port to send requests to
for the desired service.
The client process can let the local host bind its local port address. The
client does not need to know its own port address, and if the server
process needs to send a reply to the client's request, the server can find
out the client's port address when it receives with recvfrom.
Set up the address structure with a local address before you make a
bind call. Use the wildcard address so your processes do not have to look
up their own internet addresses. bind and its parameters are described
in the following table.
Include files:
#include <sys/types.h>
#include <netinet/in.h>
#include <sys/socket.h>
System call:
bind (s, addr, addrlen)
int s;
struct sockaddr *addr;
int addrlen;
Chapter 4
Using Internet Datagram Sockets
Writing the Server and Client Processes
93

Advertisement

Table of Contents
loading

Table of Contents