Top: Streams: npserver

>     #include <pstreams.h>

>     class npserver {
>         npserver(string pipename);
>         bool serve(namedpipe& client, int timeout = -1);
>     }

The npserver class is used on the server side of an interprocess communication channel. It listens to connections on the specified named pipe or a local UNIX socket and for each connection provides a namedpipe object for exchanging data with the peer.

Please, read the introduction to namedpipe first.

npserver::npserver(string pipename) creates a named pipe server object. The named pipe or a local socket is actually created during the first call to serve() for this object.

bool npserver::serve(namedpipe& client, int timeout = -1) polls the pipe for connection requests. If there is a connection request from a client, serve() opens and prepares the supplied namedpipe object for communicating with the client, i.e. client will be active upon return from serve(). The second optional parameter timeout specifies the amount of time in milliseconds to wait for a connection request. If timeout is 0 serve() will return immediately; if it's -1 serve() will wait infinitely. This function returns true if there is a connection request and the client object is active, or false if the call has timed out.

See also: namedpipe, Networking examples

PTypes home