<
html
>
<
head
>
<
title
>PTypes: networking: ipstmserver</
title
>
<
meta
http-equiv
=
"Content-Type"
content
=
"text/html; charset=iso-8859-1"
>
<
link
rel
=
"stylesheet"
href
=
"styles.css"
>
</
head
>
<
body
bgcolor
=
"#FFFFFF"
leftmargin
=
"40"
marginwidth
=
"40"
>
<
p
><
a
href
=
"../index.html"
><
img
src
=
"title-21.png"
width
=
"253"
height
=
"39"
alt
=
"C++ Portable Types Library (PTypes) Version 2.1"
border
=
"0"
></
a
>
<
hr
size
=
"1"
noshade>
<
p
class
=
"hpath"
><
a
href
=
"index.html"
>Top</
a
>: <
a
href
=
"inet.html"
>Networking</
a
>:
ipstmserver</
p
>
<
blockquote
>
<
pre
class
=
"lang"
>#include <
pinet.h
>
class ipstmserver {
ipstmserver();
int bind(ipaddress ip, int port);
int bindall(int port);
bool poll(int bindnum = -1, int timeout = 0);
bool serve(ipstream& client, int bindnum = -1, int timeout = -1);
virtual void sockopt(int socket);
}</
pre
>
</
blockquote
>
<
p
>The <
span
class
=
"lang"
>ipstmserver</
span
> class is used on the server side
of a stream-oriented client-server application. It bounds itself to a specified
port/address and waits until a connection request is received from a client host.
For each connection request a server application performs some actions and returns
to the waiting state. For better performance your daemon may start a new thread
for each client connection.</
p
>
<
p
><
span
class
=
"lang"
>Ipstmserver</
span
> can generate exceptions of type <
span
class
=
"lang"
>(estream*)</
span
>
with a corresponding error code and a message string.</
p
>
<
p
><
span
class
=
"def"
>ipstmserver::ipstmserver()</
span
> constructs an <
span
class
=
"lang"
>ipstmserver</
span
>
object.</
p
>
<
p
><
span
class
=
"def"
>int ipstmserver::bind(ipaddress ip, int port)</
span
> binds
the server to the specified local IP address and port number. This function can
be called multiple times for different local addresses and port numbers. <
span
class
=
"lang"
>Bind()</
span
>
returns a value that can be used later in call to <
span
class
=
"lang"
>poll()</
span
>
and <
span
class
=
"lang"
>serve()</
span
> as the parameter <
span
class
=
"lang"
>bindnum</
span
>.</
p
>
<
p
><
span
class
=
"def"
>int ipstmserver::bindall(int port)</
span
> binds the server
to all local IP addresses on the specified port number. Can be called multiple
times for different port numbers. <
span
class
=
"lang"
>Bindall()</
span
> returns
a value that can be used later in call to <
span
class
=
"lang"
>poll()</
span
> and
<
span
class
=
"lang"
>serve()</
span
> as the parameter <
span
class
=
"lang"
>bindnum</
span
>.</
p
>
<
p
><
span
class
=
"def"
>bool ipstmserver::poll(int bindnum = -1, int timeout = 0)</
span
>
polls the listening sockets for connection requests. <
span
class
=
"lang"
>Bindnum</
span
>
specifies the socket number reutrned by <
span
class
=
"lang"
>bind()</
span
> or <
span
class
=
"lang"
>bindall()</
span
>.
If <
span
class
=
"lang"
>bindnum</
span
> is -1 <
span
class
=
"lang"
>poll()</
span
> tests
all sockets. The second parameter <
span
class
=
"lang"
>timeout</
span
> specifies
the amount of time in milliseconds to wait for a connection request. If <
span
class
=
"lang"
>timeout</
span
>
is 0 <
span
class
=
"lang"
>poll()</
span
> returns immediately; if it's -1 <
span
class
=
"lang"
>poll()</
span
>
waits infinitely. This function returns <
span
class
=
"lang"
>true</
span
> if there
is a new connection request waiting for processing.</
p
>
<
p
><
span
class
=
"def"
>bool ipstmserver::serve(ipstream& client, int bindnum
= -1, int timeout = -1)</
span
> polls the specified bound sockets for connection
requests. If there is a connection request, <
span
class
=
"lang"
>serve()</
span
>
opens and prepares the supplied <
span
class
=
"lang"
>ipstream</
span
> object for
communicating with the client, i.e. <
span
class
=
"lang"
>client</
span
> will be active
upon return from <
span
class
=
"lang"
>serve()</
span
> and will contain the peer IP
address and the port number. The meanings of <
span
class
=
"lang"
>bindnum</
span
>
and <
span
class
=
"lang"
>timeout</
span
> are the same as for <
span
class
=
"lang"
>poll()</
span
>
except that the default value for <
span
class
=
"lang"
>timeout</
span
> in this case
is -1, i.e. wait infinitely. This function returns <
span
class
=
"lang"
>true</
span
>
if there is a new connection request and <
span
class
=
"lang"
>client</
span
> is active,
or <
span
class
=
"lang"
>false</
span
> if the call has timed out.</
p
>
<
p
><
span
class
=
"def"
>virtual void ipstmserver::sockopt(int socket)</
span
> - override this method in a descendant class if you want to set up additional socket options (normally, by calling <
span
class
=
"lang"
>setsockopt()</
span
>).</
p
>
<
p
class
=
"seealso"
>See also: <
a
href
=
"inet.ipstream.html"
>ipstream</
a
>, <
a
href
=
"inet.utils.html"
>Utilities</
a
>,
<
a
href
=
"inet.examples.html"
>Examples</
a
></
p
>
<
hr
size
=
"1"
>
<
a
href
=
"../index.html"
class
=
"ns"
>PTypes home</
a
>
</
body
>
</
html
>