  | 
»  | 
 | 
  
 | 
 | 
This section discusses the calls your client process must make to
connect with and be served by a server process. Creating a Socket |    |  
 The client process
must call socket to create a communication
endpoint. socket and its parameters
are described in the following table. - Include files:
 #include <sys/types.h>  #include <sys/socket.h>  |  
 - System call:
 s = socket(af, type, protocol)  int af, type, protocol;  |  
 - Function result:
 socket number (HP-UX file descriptor), -1
if failure occurs. - Example:
 s = socket (AF_UNIX, SOCK_STREAM, 0);  |  
 
 The socket number returned is the socket descriptor for the
newly created socket. This number is an HP-UX file descriptor and
can be used for reading, writing or any standard file system calls
after a BSD Sockets connection is established. A socket descriptor
is treated like a file descriptor for an open file. The client process should create sockets before requesting
a connection. Refer to the socket(2) man
page for more information on socket. Requesting a Connection |    |  
 Once the server process is listening for connection requests, the client process
can request a connection with the connect
 call. connect
and its parameters are described in the following table. - Include files:
 #include <sys/types.h>  #include <sys/un.h>  #include <sys/socket.h>  |  
 - System call:
 connect(s, addr, addrlen)  int s;  struct sockaddr_un *addr;  int addrlen;  |  
 - Function result:
 0 if connect is successful, -1 if failure
occurs. 
 Example: struct sockaddr_un peeraddr; ... connect (s, &peeraddr, sizeof(struct sockaddr_un));  |  
 connect initiates a connection.
When the connection is ready, the client process completes its connect
call and the server process can complete its accept
call.   |    |   |    |    | NOTE: The client process does not get feedback that the server
process has completed the accept
call. As soon as the connect call
returns, the client process can send data. |    |    |   |    |  
 When to Request a ConnectionThe client process should request a connection after socket
is created and after server socket has a listening socket. Refer
to the connect(2) man page for
more information on connect.  
 |