📄 inet.ipstmserver.html
字号:
<html><!-- #BeginTemplate "/Templates/tmpl.dwt" --><head><!-- #BeginEditable "doctitle" --> <title>PTypes: networking: ipstmserver</title><!-- #EndEditable --> <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-1.7.gif" width="213" height="34" alt="C++ Portable Types Library (PTypes) Version 1.7" border="0"></a> <hr noshade><!-- #BeginEditable "body" --> <p class="hpath"><a href="index.html">Top</a>: <a href="inet.html">Networking</a>: ipstmserver</p><blockquote> <pre class="lang">#include <pinet.h>ipstmserver::ipstmserver();void ipstmserver::bind(ipaddress ip, int port);void ipstmserver::bindall(int port);bool ipstmserver::poll(int bindnum = -1, int timeout = 0);bool ipstmserver::serve(ipstream& client, int bindnum = -1, int timeout = -1);</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">void 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.</p><p><span class="def">void ipstmserver::bindall(int port)</span> binds the server to all local IP address on the specified port number. Can be called multiple times for different port numbers.</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 to test. The numbering of bound sockets corresponds to the order in which functions <span class="lang">bind()</span> or <span class="lang">bindall()</span> were called, starting from 0. If <span class="lang">bindnum</span> is -1 <span class="lang">poll()</span> will test 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> will return immediately; if it's -1 <span class="lang">poll()</span> will wait 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 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><!-- #EndEditable --> <hr size="1"><a href="../index.html" class="ns">PTypes home</a></body><!-- #EndTemplate --></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -