TCP/IP Programming Manual

6. Shut down the socket (optional for TCP; not done for UDP or RAW).
7. Close the socket.
Designating the NonStop TCP/IP, TCPSAM, or TCP6SAM Process Name
To create a socket, the socket-interface library opens a file to communicate with the NonStop
TCP/IP, TCPSAM, or TCP6SAM process. Therefore, the socket library must know the name of this
process before any sockets are created. Programs can specify this process explicitly by calling the
function socket_set_inet_name.
If a program has not called socket_set_inet_name before creating a socket, the function that
creates a socket makes default assumptions about the process name. The function uses the value
of TCPIP^PROCESS^NAME, if it exists (usually declared using the DEFINE command); otherwise,
it uses the process name $ZTC0. See Using the DEFINE Command (page 29), for more information
about the value of TCPIP^PROCESS^NAME.
Creating a Socket
A program calls the socket function to create a socket. The socket function returns a descriptor.
The program passes this socket descriptor to subsequent calls for operations on that socket.
Binding a Socket
A program can associate the socket with a local address and port number by calling the bind
function. This call is optional for client programs. If the program does not call bind, the connect
function performs the binding.
For UDP and RAW, calls to bind and connect are unnecessary because UDP and RAW datagrams
contain all the addressing information needed. UDP datagrams contain information about source
and destination addresses and port numbers. RAW datagrams contain information about source
and destination addresses; however, unlike UDP, the RAW datagrams use protocol numbers instead
of port numbers. You specify the protocol number in the socket call.
Connecting a Socket
The connect function associates a remote address and port number with the socket. For TCP,
connect issues a request for an active connection. For UDP and RAW, no active connection
exists; connect merely serves as a convenient means to permanently specify the remote address
and port number (or protocol number) so that each call to transfer data does not need to specify
this information. For UDP or RAW, your program can either call connect to specify the remote
address and port/protocol number once, or the program can use the sendto or recvfrom
routines.
Transferring Data
Two sets of routines are provided for sending and receiving data. One set, the send and recv
routines, uses the remote address and port number specified for the socket in a previous call to
connect. The other set, the sendto and recvfrom routines, uses the remote address and port
number passed as an argument in the call. The sendto and recvfrom routines are provided for
use with connectionless protocols (UDP and RAW) in programs that do not call connect.
Shutting Down and Closing a Socket
The shutdown routine shuts down data transfer on an actively connected TCP socket, either
partially or completely (preventing further reads, writes, or both). Calling shutdown is optional;
if a program does not call shutdown, a call to the CLOSE or FILE_CLOSE_ procedure performs
the shutdown procedure. Because shutdown applies to an active connection, a program using
UDP sockets or raw sockets does not need to call this routine.
When communication is complete, your program must close the socket explicitly by issuing a call
to FILE_CLOSE_ or CLOSE, passing it the socket number as is done for the socket routine calls.
36 Introduction to Programming to the Guardian Sockets Library