summaryrefslogtreecommitdiffstats
path: root/doc/html/ntqserversocket.html
blob: 976dc8163bb6fe4e5a5c31b2f6deb4f0185d387b (plain)
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- /home/espenr/tmp/qt-3.3.8-espenr-2499/qt-x11-free-3.3.8/src/network/qserversocket.cpp:53 -->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>TQServerSocket Class</title>
<style type="text/css"><!--
fn { margin-left: 1cm; text-indent: -1cm; }
a:link { color: #004faf; text-decoration: none }
a:visited { color: #672967; text-decoration: none }
body { background: #ffffff; color: black; }
--></style>
</head>
<body>

<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr bgcolor="#E5E5E5">
<td valign=center>
 <a href="index.html">
<font color="#004faf">Home</font></a>
 | <a href="classes.html">
<font color="#004faf">All&nbsp;Classes</font></a>
 | <a href="mainclasses.html">
<font color="#004faf">Main&nbsp;Classes</font></a>
 | <a href="annotated.html">
<font color="#004faf">Annotated</font></a>
 | <a href="groups.html">
<font color="#004faf">Grouped&nbsp;Classes</font></a>
 | <a href="functions.html">
<font color="#004faf">Functions</font></a>
</td>
<td align="right" valign="center"><img src="logo32.png" align="right" width="64" height="32" border="0"></td></tr></table><h1 align=center>TQServerSocket Class Reference<br><small>[<a href="network.html">network module</a>]</small></h1>

<p>The TQServerSocket class provides a TCP-based server.
<a href="#details">More...</a>
<p><tt>#include &lt;<a href="qserversocket-h.html">ntqserversocket.h</a>&gt;</tt>
<p>Inherits <a href="ntqobject.html">TQObject</a>.
<p><a href="qserversocket-members.html">List of all member functions.</a>
<h2>Public Members</h2>
<ul>
<li class=fn><a href="#TQServerSocket"><b>TQServerSocket</b></a> ( Q_UINT16&nbsp;port, int&nbsp;backlog = 1, TQObject&nbsp;*&nbsp;parent = 0, const&nbsp;char&nbsp;*&nbsp;name = 0 )</li>
<li class=fn><a href="#TQServerSocket-2"><b>TQServerSocket</b></a> ( const&nbsp;TQHostAddress&nbsp;&amp;&nbsp;address, Q_UINT16&nbsp;port, int&nbsp;backlog = 1, TQObject&nbsp;*&nbsp;parent = 0, const&nbsp;char&nbsp;*&nbsp;name = 0 )</li>
<li class=fn><a href="#TQServerSocket-3"><b>TQServerSocket</b></a> ( TQObject&nbsp;*&nbsp;parent = 0, const&nbsp;char&nbsp;*&nbsp;name = 0 )</li>
<li class=fn>virtual <a href="#~TQServerSocket"><b>~TQServerSocket</b></a> ()</li>
<li class=fn>bool <a href="#ok"><b>ok</b></a> () const</li>
<li class=fn>Q_UINT16 <a href="#port"><b>port</b></a> () const</li>
<li class=fn>int <a href="#socket"><b>socket</b></a> () const</li>
<li class=fn>virtual void <a href="#setSocket"><b>setSocket</b></a> ( int&nbsp;socket )</li>
<li class=fn>TQHostAddress <a href="#address"><b>address</b></a> () const</li>
<li class=fn>virtual void <a href="#newConnection"><b>newConnection</b></a> ( int&nbsp;socket ) = 0</li>
</ul>
<h2>Protected Members</h2>
<ul>
<li class=fn>TQSocketDevice * <a href="#socketDevice"><b>socketDevice</b></a> ()</li>
</ul>
<hr><a name="details"></a><h2>Detailed Description</h2>


The TQServerSocket class provides a TCP-based server.

<p> 

<p> This class is a convenience class for accepting incoming TCP
connections. You can specify the port or have TQServerSocket pick
one, and listen on just one address or on all the machine's
addresses.
<p> Using the API is very simple: subclass TQServerSocket, call the
constructor of your choice, and implement <a href="#newConnection">newConnection</a>() to
handle new incoming connections. There is nothing more to do.
<p> (Note that due to lack of support in the underlying APIs,
TQServerSocket cannot accept or reject connections conditionally.)
<p> <p>See also <a href="ntqsocket.html">TQSocket</a>, <a href="ntqsocketdevice.html">TQSocketDevice</a>, <a href="ntqhostaddress.html">TQHostAddress</a>, <a href="ntqsocketnotifier.html">TQSocketNotifier</a>, and <a href="io.html">Input/Output and Networking</a>.

<hr><h2>Member Function Documentation</h2>
<h3 class=fn><a name="TQServerSocket"></a>TQServerSocket::TQServerSocket ( Q_UINT16&nbsp;port, int&nbsp;backlog = 1, <a href="ntqobject.html">TQObject</a>&nbsp;*&nbsp;parent = 0, const&nbsp;char&nbsp;*&nbsp;name = 0 )
</h3>
Creates a server socket object, that will serve the given <em>port</em>
on all the addresses of this host. If <em>port</em> is 0, TQServerSocket
will pick a suitable port in a system-dependent manner. Use <em>backlog</em> to specify how many pending connections the server can
have.
<p> The <em>parent</em> and <em>name</em> arguments are passed on to the <a href="ntqobject.html">TQObject</a>
constructor.
<p> <b>Warning:</b> On Tru64 Unix systems a value of 0 for <em>backlog</em> means
that you don't accept any connections at all; you should specify a
value larger than 0.

<h3 class=fn><a name="TQServerSocket-2"></a>TQServerSocket::TQServerSocket ( const&nbsp;<a href="ntqhostaddress.html">TQHostAddress</a>&nbsp;&amp;&nbsp;address, Q_UINT16&nbsp;port, int&nbsp;backlog = 1, <a href="ntqobject.html">TQObject</a>&nbsp;*&nbsp;parent = 0, const&nbsp;char&nbsp;*&nbsp;name = 0 )
</h3>
Creates a server socket object, that will serve the given <em>port</em>
only on the given <em>address</em>. Use <em>backlog</em> to specify how many
pending connections the server can have.
<p> The <em>parent</em> and <em>name</em> arguments are passed on to the <a href="ntqobject.html">TQObject</a>
constructor.
<p> <b>Warning:</b> On Tru64 Unix systems a value of 0 for <em>backlog</em> means
that you don't accept any connections at all; you should specify a
value larger than 0.

<h3 class=fn><a name="TQServerSocket-3"></a>TQServerSocket::TQServerSocket ( <a href="ntqobject.html">TQObject</a>&nbsp;*&nbsp;parent = 0, const&nbsp;char&nbsp;*&nbsp;name = 0 )
</h3>
Construct an empty server socket.
<p> This constructor, in combination with <a href="#setSocket">setSocket</a>(), allows us to
use the TQServerSocket class as a wrapper for other socket types
(e.g. Unix Domain Sockets under Unix).
<p> The <em>parent</em> and <em>name</em> arguments are passed on to the <a href="ntqobject.html">TQObject</a>
constructor.
<p> <p>See also <a href="#setSocket">setSocket</a>().

<h3 class=fn><a name="~TQServerSocket"></a>TQServerSocket::~TQServerSocket ()<tt> [virtual]</tt>
</h3>
Destroys the socket.
<p> This causes any backlogged connections (connections that have
reached the host, but not yet been completely set up by calling
<a href="ntqsocketdevice.html#accept">TQSocketDevice::accept</a>()) to be severed.
<p> Existing connections continue to exist; this only affects the
acceptance of new connections.

<h3 class=fn><a href="ntqhostaddress.html">TQHostAddress</a> <a name="address"></a>TQServerSocket::address () const
</h3>
Returns the address on which this object listens, or 0.0.0.0 if
this object listens on more than one address. <a href="#ok">ok</a>() must be TRUE
before calling this function.
<p> <p>See also <a href="#port">port</a>() and <a href="ntqsocketdevice.html#address">TQSocketDevice::address</a>().

<h3 class=fn>void <a name="newConnection"></a>TQServerSocket::newConnection ( int&nbsp;socket )<tt> [pure virtual]</tt>
</h3>

<p> This pure virtual function is responsible for setting up a new
incoming connection. <em>socket</em> is the fd (file descriptor) for the
newly accepted connection.

<h3 class=fn>bool <a name="ok"></a>TQServerSocket::ok () const
</h3>
Returns TRUE if the construction succeeded; otherwise returns FALSE.

<h3 class=fn>Q_UINT16 <a name="port"></a>TQServerSocket::port () const
</h3>
Returns the port number on which this server socket listens. This
is always non-zero; if you specify 0 in the constructor,
TQServerSocket will pick a non-zero port itself. <a href="#ok">ok</a>() must be TRUE
before calling this function.
<p> <p>See also <a href="#address">address</a>() and <a href="ntqsocketdevice.html#port">TQSocketDevice::port</a>().

<p>Example: <a href="httpd-example.html#x726">network/httpd/httpd.cpp</a>.
<h3 class=fn>void <a name="setSocket"></a>TQServerSocket::setSocket ( int&nbsp;socket )<tt> [virtual]</tt>
</h3>
Sets the socket to use <em>socket</em>. bind() and listen() should
already have been called for <em>socket</em>.
<p> This allows us to use the TQServerSocket class as a wrapper for
other socket types (e.g. Unix Domain Sockets).

<h3 class=fn>int <a name="socket"></a>TQServerSocket::socket () const
</h3>
Returns the operating system socket.

<h3 class=fn><a href="ntqsocketdevice.html">TQSocketDevice</a>&nbsp;* <a name="socketDevice"></a>TQServerSocket::socketDevice ()<tt> [protected]</tt>
</h3>
Returns a pointer to the internal socket device. The returned
pointer is 0 if there is no connection or pending connection.
<p> There is normally no need to manipulate the socket device directly
since this class does all the necessary setup for most client or
server socket applications.

<!-- eof -->
<hr><p>
This file is part of the <a href="index.html">TQt toolkit</a>.
Copyright &copy; 1995-2007
<a href="http://www.trolltech.com/">Trolltech</a>. All Rights Reserved.<p><address><hr><div align=center>
<table width=100% cellspacing=0 border=0><tr>
<td>Copyright &copy; 2007
<a href="troll.html">Trolltech</a><td align=center><a href="trademarks.html">Trademarks</a>
<td align=right><div align=right>TQt 3.3.8</div>
</table></div></address></body>
</html>