source: trunk/doc/html/qserversocket.html

Last change on this file was 190, checked in by rudi, 14 years ago

reference documentation added

File size: 9.1 KB
Line 
1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
2<!-- /home/espenr/tmp/qt-3.3.8-espenr-2499/qt-x11-free-3.3.8/src/network/qserversocket.cpp:53 -->
3<html>
4<head>
5<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
6<title>QServerSocket Class</title>
7<style type="text/css"><!--
8fn { margin-left: 1cm; text-indent: -1cm; }
9a:link { color: #004faf; text-decoration: none }
10a:visited { color: #672967; text-decoration: none }
11body { background: #ffffff; color: black; }
12--></style>
13</head>
14<body>
15
16<table border="0" cellpadding="0" cellspacing="0" width="100%">
17<tr bgcolor="#E5E5E5">
18<td valign=center>
19 <a href="index.html">
20<font color="#004faf">Home</font></a>
21 | <a href="classes.html">
22<font color="#004faf">All&nbsp;Classes</font></a>
23 | <a href="mainclasses.html">
24<font color="#004faf">Main&nbsp;Classes</font></a>
25 | <a href="annotated.html">
26<font color="#004faf">Annotated</font></a>
27 | <a href="groups.html">
28<font color="#004faf">Grouped&nbsp;Classes</font></a>
29 | <a href="functions.html">
30<font color="#004faf">Functions</font></a>
31</td>
32<td align="right" valign="center"><img src="logo32.png" align="right" width="64" height="32" border="0"></td></tr></table><h1 align=center>QServerSocket Class Reference<br><small>[<a href="network.html">network module</a>]</small></h1>
33
34<p>The QServerSocket class provides a TCP-based server.
35<a href="#details">More...</a>
36<p><tt>#include &lt;<a href="qserversocket-h.html">qserversocket.h</a>&gt;</tt>
37<p>Inherits <a href="qobject.html">QObject</a>.
38<p><a href="qserversocket-members.html">List of all member functions.</a>
39<h2>Public Members</h2>
40<ul>
41<li class=fn><a href="#QServerSocket"><b>QServerSocket</b></a> ( Q_UINT16&nbsp;port, int&nbsp;backlog = 1, QObject&nbsp;*&nbsp;parent = 0, const&nbsp;char&nbsp;*&nbsp;name = 0 )</li>
42<li class=fn><a href="#QServerSocket-2"><b>QServerSocket</b></a> ( const&nbsp;QHostAddress&nbsp;&amp;&nbsp;address, Q_UINT16&nbsp;port, int&nbsp;backlog = 1, QObject&nbsp;*&nbsp;parent = 0, const&nbsp;char&nbsp;*&nbsp;name = 0 )</li>
43<li class=fn><a href="#QServerSocket-3"><b>QServerSocket</b></a> ( QObject&nbsp;*&nbsp;parent = 0, const&nbsp;char&nbsp;*&nbsp;name = 0 )</li>
44<li class=fn>virtual <a href="#~QServerSocket"><b>~QServerSocket</b></a> ()</li>
45<li class=fn>bool <a href="#ok"><b>ok</b></a> () const</li>
46<li class=fn>Q_UINT16 <a href="#port"><b>port</b></a> () const</li>
47<li class=fn>int <a href="#socket"><b>socket</b></a> () const</li>
48<li class=fn>virtual void <a href="#setSocket"><b>setSocket</b></a> ( int&nbsp;socket )</li>
49<li class=fn>QHostAddress <a href="#address"><b>address</b></a> () const</li>
50<li class=fn>virtual void <a href="#newConnection"><b>newConnection</b></a> ( int&nbsp;socket ) = 0</li>
51</ul>
52<h2>Protected Members</h2>
53<ul>
54<li class=fn>QSocketDevice * <a href="#socketDevice"><b>socketDevice</b></a> ()</li>
55</ul>
56<hr><a name="details"></a><h2>Detailed Description</h2>
57
58
59The QServerSocket class provides a TCP-based server.
60
61<p>
62
63<p> This class is a convenience class for accepting incoming TCP
64connections. You can specify the port or have QServerSocket pick
65one, and listen on just one address or on all the machine's
66addresses.
67<p> Using the API is very simple: subclass QServerSocket, call the
68constructor of your choice, and implement <a href="#newConnection">newConnection</a>() to
69handle new incoming connections. There is nothing more to do.
70<p> (Note that due to lack of support in the underlying APIs,
71QServerSocket cannot accept or reject connections conditionally.)
72<p> <p>See also <a href="qsocket.html">QSocket</a>, <a href="qsocketdevice.html">QSocketDevice</a>, <a href="qhostaddress.html">QHostAddress</a>, <a href="qsocketnotifier.html">QSocketNotifier</a>, and <a href="io.html">Input/Output and Networking</a>.
73
74<hr><h2>Member Function Documentation</h2>
75<h3 class=fn><a name="QServerSocket"></a>QServerSocket::QServerSocket ( Q_UINT16&nbsp;port, int&nbsp;backlog = 1, <a href="qobject.html">QObject</a>&nbsp;*&nbsp;parent = 0, const&nbsp;char&nbsp;*&nbsp;name = 0 )
76</h3>
77Creates a server socket object, that will serve the given <em>port</em>
78on all the addresses of this host. If <em>port</em> is 0, QServerSocket
79will pick a suitable port in a system-dependent manner. Use <em>backlog</em> to specify how many pending connections the server can
80have.
81<p> The <em>parent</em> and <em>name</em> arguments are passed on to the <a href="qobject.html">QObject</a>
82constructor.
83<p> <b>Warning:</b> On Tru64 Unix systems a value of 0 for <em>backlog</em> means
84that you don't accept any connections at all; you should specify a
85value larger than 0.
86
87<h3 class=fn><a name="QServerSocket-2"></a>QServerSocket::QServerSocket ( const&nbsp;<a href="qhostaddress.html">QHostAddress</a>&nbsp;&amp;&nbsp;address, Q_UINT16&nbsp;port, int&nbsp;backlog = 1, <a href="qobject.html">QObject</a>&nbsp;*&nbsp;parent = 0, const&nbsp;char&nbsp;*&nbsp;name = 0 )
88</h3>
89Creates a server socket object, that will serve the given <em>port</em>
90only on the given <em>address</em>. Use <em>backlog</em> to specify how many
91pending connections the server can have.
92<p> The <em>parent</em> and <em>name</em> arguments are passed on to the <a href="qobject.html">QObject</a>
93constructor.
94<p> <b>Warning:</b> On Tru64 Unix systems a value of 0 for <em>backlog</em> means
95that you don't accept any connections at all; you should specify a
96value larger than 0.
97
98<h3 class=fn><a name="QServerSocket-3"></a>QServerSocket::QServerSocket ( <a href="qobject.html">QObject</a>&nbsp;*&nbsp;parent = 0, const&nbsp;char&nbsp;*&nbsp;name = 0 )
99</h3>
100Construct an empty server socket.
101<p> This constructor, in combination with <a href="#setSocket">setSocket</a>(), allows us to
102use the QServerSocket class as a wrapper for other socket types
103(e.g. Unix Domain Sockets under Unix).
104<p> The <em>parent</em> and <em>name</em> arguments are passed on to the <a href="qobject.html">QObject</a>
105constructor.
106<p> <p>See also <a href="#setSocket">setSocket</a>().
107
108<h3 class=fn><a name="~QServerSocket"></a>QServerSocket::~QServerSocket ()<tt> [virtual]</tt>
109</h3>
110Destroys the socket.
111<p> This causes any backlogged connections (connections that have
112reached the host, but not yet been completely set up by calling
113<a href="qsocketdevice.html#accept">QSocketDevice::accept</a>()) to be severed.
114<p> Existing connections continue to exist; this only affects the
115acceptance of new connections.
116
117<h3 class=fn><a href="qhostaddress.html">QHostAddress</a> <a name="address"></a>QServerSocket::address () const
118</h3>
119Returns the address on which this object listens, or 0.0.0.0 if
120this object listens on more than one address. <a href="#ok">ok</a>() must be TRUE
121before calling this function.
122<p> <p>See also <a href="#port">port</a>() and <a href="qsocketdevice.html#address">QSocketDevice::address</a>().
123
124<h3 class=fn>void <a name="newConnection"></a>QServerSocket::newConnection ( int&nbsp;socket )<tt> [pure virtual]</tt>
125</h3>
126
127<p> This pure virtual function is responsible for setting up a new
128incoming connection. <em>socket</em> is the fd (file descriptor) for the
129newly accepted connection.
130
131<h3 class=fn>bool <a name="ok"></a>QServerSocket::ok () const
132</h3>
133Returns TRUE if the construction succeeded; otherwise returns FALSE.
134
135<h3 class=fn>Q_UINT16 <a name="port"></a>QServerSocket::port () const
136</h3>
137Returns the port number on which this server socket listens. This
138is always non-zero; if you specify 0 in the constructor,
139QServerSocket will pick a non-zero port itself. <a href="#ok">ok</a>() must be TRUE
140before calling this function.
141<p> <p>See also <a href="#address">address</a>() and <a href="qsocketdevice.html#port">QSocketDevice::port</a>().
142
143<p>Example: <a href="httpd-example.html#x726">network/httpd/httpd.cpp</a>.
144<h3 class=fn>void <a name="setSocket"></a>QServerSocket::setSocket ( int&nbsp;socket )<tt> [virtual]</tt>
145</h3>
146Sets the socket to use <em>socket</em>. bind() and listen() should
147already have been called for <em>socket</em>.
148<p> This allows us to use the QServerSocket class as a wrapper for
149other socket types (e.g. Unix Domain Sockets).
150
151<h3 class=fn>int <a name="socket"></a>QServerSocket::socket () const
152</h3>
153Returns the operating system socket.
154
155<h3 class=fn><a href="qsocketdevice.html">QSocketDevice</a>&nbsp;* <a name="socketDevice"></a>QServerSocket::socketDevice ()<tt> [protected]</tt>
156</h3>
157Returns a pointer to the internal socket device. The returned
158pointer is 0 if there is no connection or pending connection.
159<p> There is normally no need to manipulate the socket device directly
160since this class does all the necessary setup for most client or
161server socket applications.
162
163<!-- eof -->
164<hr><p>
165This file is part of the <a href="index.html">Qt toolkit</a>.
166Copyright &copy; 1995-2007
167<a href="http://www.trolltech.com/">Trolltech</a>. All Rights Reserved.<p><address><hr><div align=center>
168<table width=100% cellspacing=0 border=0><tr>
169<td>Copyright &copy; 2007
170<a href="troll.html">Trolltech</a><td align=center><a href="trademarks.html">Trademarks</a>
171<td align=right><div align=right>Qt 3.3.8</div>
172</table></div></address></body>
173</html>
Note: See TracBrowser for help on using the repository browser.