5. Server Side

To establish a server under the inetd server, you can use

    COMSTACK cs_createbysocket(int socket, CS_TYPE type, int blocking,
                               int protocol);
   

The socket parameter is an established socket (when your application is invoked from inetd, the socket will typically be 0. The following parameters are identical to the ones for cs_create.

    int cs_bind(COMSTACK handle, void *address, int mode)
   

Binds a local address to the endpoint. Read about addresses below. The mode parameter should be either CS_CLIENT or CS_SERVER.

    int cs_listen(COMSTACK handle, char *addr, int *addrlen);
   

Call this to process incoming events on an endpoint that has been bound in listening mode. It will return 0 to indicate that the connect request has been received, 1 to signal a partial reception, and -1 to indicate an error condition.

    COMSTACK cs_accept(COMSTACK handle);
   

This finalizes the server-side association establishment, after cs_listen has completed successfully. It returns a new connection endpoint, which represents the new association. The application will typically wish to fork off a process to handle the association at this point, and continue listen for new connections on the old handle.

You can use the call

    const char *cs_addrstr(COMSTACK);
   

on an established connection to retrieve the host-name of the remote host.

Note

You may need to use this function with some care if your name server service is slow or unreliable.