Root/
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 | < html > <!-- #BeginTemplate "/Templates/tmpl.dwt" --> <!-- DW6 --> < 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-21.png" width = "253" height = "39" alt = "C++ Portable Types Library (PTypes) Version 2.1" border = "0" ></ a > < hr size = "1" 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 > 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 > <!-- #EndEditable --> < hr size = "1" > < a href = "../index.html" class = "ns" >PTypes home</ a > </ body > <!-- #EndTemplate --> </ html > |
Source at commit 8edbcdac0d39 created 11 years 11 months ago. By Nathan Adams, initial commit |
---|