Previous topic |
Next topic |
Contents |
Contact z/OS |
Library |
PDF
Multitasking C socket sample program z/OS Communications Server: IP Sockets Application Programming Interface Guide and Reference SC27-3660-00 |
|
The first sample program is the server in the C language.
It allocates a socket, binds to a port, calls listen() to perform
a passive open, and uses select() to block until a client request
arrives. When a client requests a connection, select() returns and
accept() is called to establish the connection.
Note: Some hosts
have more than one network address. By specifying a particular network
address for the bind() call, a server specifies that it wants to honor
connections from one particular network address only. If the server
specifies the constant INADDR_ANY for this address, it accepts connections
from any of the machine’s network addresses.
This program uses the Multitasking Facility (MTF). The server has started a number of subtasks with the MTF task initialization service tinit(). When the server has accepted a connection, it calls tsched() to start the subtask that will handle the client. The server then uses givesocket() and takesocket() to pass the connection to the subtask. When the connection has been passed to the subtask, the main loop blocks in select() waiting for another client. The second program is the subtask in C. When it begins, it does a takesocket(). It was passed two 8-byte names that define the parent task from which it will obtain the socket. After it gets the socket, it sends a message to this new client and then waits for the client to send a message back. The third program is the client in C. It allocates a socket,
binds to a port, and connects to a server port that is passed as the
second parameter port number 691. Then it has a conversation with
the server (actually the server’s subtask) sending and receiving messages
alternatively.
Notes:
|
Copyright IBM Corporation 1990, 2014
|