TCP/IP Programming Manual

return 0;
}
sin.sin_family = AF_INET;
/*
* Create a socket so that we can use it for
* accepting the connection.
*/
if ((sock = socket (AF_INET, SOCK_STREAM, 0)) < 0) {
perror ("socket");
return 0;
}
/*
* This is a waited socket, but we use the trick of
* nowait accept_nw2, because this does just what we
* need (accept a connection as a new socket).
*/
if (accept_nw2(sock, (struct sockaddr*)&sin, 01) < 0) {
perror ("accept_nw2");
return 0;
}
return 1;
}
TCP Client and Server Programs
Table 1 lists the steps performed by a TCP client and a TCP server in waited operations. The calls
used to perform each step are given in parentheses; calls spelled out in uppercase letters are
NonStop operating system procedure calls.
Table 1 TCP—Waited Client and Server Steps
ServerClient
Optionally, set NonStop TCP/IP or TCP6SAM
process name (socket_set_inet_name).
1.Optionally, set NonStop TCP/IP or
TCP6SAM process name
(socket_set_inet_name).
1.
Create a socket (socket).2.Create a socket (socket).2.
Bind the socket to a well-known port (bind).3.Optionally, bind the socket to any port
(bind).
3.
Listen for connections (listen).4.Connect the socket to the server
(connect).
4.
Accept an incoming connection on a new socket
(accept).
5.
Start data transfer on the new socket (recv and/or
send, usually in a loop).
6.Start data transfer (send and/or recv,
usually in a loop).
5.
Optionally, shut down one or both sockets
(shutdown).
7.Optionally, shut down the socket
(shutdown).
6.
Close the socket (CLOSE or FILE_CLOSE_).8.Close the socket (CLOSE or
FILE_CLOSE_).
7.
Table 2 (page 40) shows the steps performed by a TCP client and a TCP server in nowait operations.
The calls used to perform each step are given in parentheses. Note the use of nowait versions of
most of the socket calls, followed by calls to the AWAITIOX procedure for completion of the call.
The nowait versions of the socket calls require the program to provide a tag parameter to identify
the particular operation. When AWAITIOX is called, it returns the tag that was passed to it in the
corresponding nowait socket call.
Sample TCP client and server programs are provided in Chapter 5.
Basic Steps for Programs 39