1
<?xml version="1.0" encoding="iso-8859-1"?>
2
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
3
<html><head><title>QAbstractSocket Class Reference</title><style>h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm }
4
a:link { color: #004faf; text-decoration: none }
5
a:visited { color: #672967; text-decoration: none }
6
td.postheader { font-family: sans-serif }
7
tr.address { font-family: sans-serif }
8
body { background: #ffffff; color: black; }
9
</style></head><body><table border="0" cellpadding="0" cellspacing="0" width="100%"><tr /><td align="left" valign="top" width="32"><img align="left" border="0" height="32" src="images/rb-logo.png" width="32" /></td><td width="1">  </td><td class="postheader" valign="center"><a href="index.html"><font color="#004faf">Home</font></a> · <a href="classes.html"><font color="#004faf">All Classes</font></a> · <a href="modules.html"><font color="#004faf">Modules</font></a></td></table><h1 align="center">QAbstractSocket Class Reference<br /><sup><sup>[<a href="qtnetwork.html">QtNetwork</a> module]</sup></sup></h1><p>The QAbstractSocket class provides the base functionality common
10
to all socket types. <a href="#details">More...</a></p>
12
<p>Inherits <a href="qiodevice.html">QIODevice</a>.</p><p>Inherited by <a href="qtcpsocket.html">QTcpSocket</a> and <a href="qudpsocket.html">QUdpSocket</a>.</p><h3>Types</h3><ul><li><div class="fn" />enum <b><a href="qabstractsocket.html#NetworkLayerProtocol-enum">NetworkLayerProtocol</a></b> { IPv4Protocol, IPv6Protocol, UnknownNetworkLayerProtocol }</li><li><div class="fn" />enum <b><a href="qabstractsocket.html#SocketError-enum">SocketError</a></b> { ConnectionRefusedError, RemoteHostClosedError, HostNotFoundError, SocketAccessError, ..., UnknownSocketError }</li><li><div class="fn" />enum <b><a href="qabstractsocket.html#SocketOption-enum">SocketOption</a></b> { LowDelayOption, KeepAliveOption, MulticastTtlOption, MulticastLoopbackOption }</li><li><div class="fn" />enum <b><a href="qabstractsocket.html#SocketState-enum">SocketState</a></b> { UnconnectedState, HostLookupState, ConnectingState, ConnectedState, ..., ClosingState }</li><li><div class="fn" />enum <b><a href="qabstractsocket.html#SocketType-enum">SocketType</a></b> { TcpSocket, UdpSocket, UnknownSocketType }</li></ul><h3>Methods</h3><ul><li><div class="fn" /><b><a href="qabstractsocket.html#QAbstractSocket">__init__</a></b> (<i>self</i>, SocketType <i>socketType</i>, QObject <i>parent</i>)</li><li><div class="fn" /><b><a href="qabstractsocket.html#abort">abort</a></b> (<i>self</i>)</li><li><div class="fn" />bool <b><a href="qabstractsocket.html#atEnd">atEnd</a></b> (<i>self</i>)</li><li><div class="fn" />int <b><a href="qabstractsocket.html#bytesAvailable">bytesAvailable</a></b> (<i>self</i>)</li><li><div class="fn" />int <b><a href="qabstractsocket.html#bytesToWrite">bytesToWrite</a></b> (<i>self</i>)</li><li><div class="fn" />bool <b><a href="qabstractsocket.html#canReadLine">canReadLine</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qabstractsocket.html#close">close</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qabstractsocket.html#connectToHost">connectToHost</a></b> (<i>self</i>, QString <i>hostName</i>, int <i>port</i>, QIODevice.OpenMode <i>mode</i> = QIODevice.ReadWrite)</li><li><div class="fn" /><b><a href="qabstractsocket.html#connectToHost-2">connectToHost</a></b> (<i>self</i>, QHostAddress <i>address</i>, int <i>port</i>, QIODevice.OpenMode <i>mode</i> = QIODevice.ReadWrite)</li><li><div class="fn" /><b><a href="qabstractsocket.html#connectToHostImplementation">connectToHostImplementation</a></b> (<i>self</i>, QString <i>hostName</i>, int <i>port</i>, QIODevice.OpenMode <i>mode</i> = QIODevice.ReadWrite)</li><li><div class="fn" /><b><a href="qabstractsocket.html#disconnectFromHost">disconnectFromHost</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qabstractsocket.html#disconnectFromHostImplementation">disconnectFromHostImplementation</a></b> (<i>self</i>)</li><li><div class="fn" />SocketError <b><a href="qabstractsocket.html#error">error</a></b> (<i>self</i>)</li><li><div class="fn" />bool <b><a href="qabstractsocket.html#flush">flush</a></b> (<i>self</i>)</li><li><div class="fn" />bool <b><a href="qabstractsocket.html#isSequential">isSequential</a></b> (<i>self</i>)</li><li><div class="fn" />bool <b><a href="qabstractsocket.html#isValid">isValid</a></b> (<i>self</i>)</li><li><div class="fn" />QHostAddress <b><a href="qabstractsocket.html#localAddress">localAddress</a></b> (<i>self</i>)</li><li><div class="fn" />int <b><a href="qabstractsocket.html#localPort">localPort</a></b> (<i>self</i>)</li><li><div class="fn" />QHostAddress <b><a href="qabstractsocket.html#peerAddress">peerAddress</a></b> (<i>self</i>)</li><li><div class="fn" />QString <b><a href="qabstractsocket.html#peerName">peerName</a></b> (<i>self</i>)</li><li><div class="fn" />int <b><a href="qabstractsocket.html#peerPort">peerPort</a></b> (<i>self</i>)</li><li><div class="fn" />QNetworkProxy <b><a href="qabstractsocket.html#proxy">proxy</a></b> (<i>self</i>)</li><li><div class="fn" />int <b><a href="qabstractsocket.html#readBufferSize">readBufferSize</a></b> (<i>self</i>)</li><li><div class="fn" />str <b><a href="qabstractsocket.html#readData">readData</a></b> (<i>self</i>, int <i>maxlen</i>)</li><li><div class="fn" />str <b><a href="qabstractsocket.html#readLineData">readLineData</a></b> (<i>self</i>, int <i>maxlen</i>)</li><li><div class="fn" /><b><a href="qabstractsocket.html#setLocalAddress">setLocalAddress</a></b> (<i>self</i>, QHostAddress <i>address</i>)</li><li><div class="fn" /><b><a href="qabstractsocket.html#setLocalPort">setLocalPort</a></b> (<i>self</i>, int <i>port</i>)</li><li><div class="fn" /><b><a href="qabstractsocket.html#setPeerAddress">setPeerAddress</a></b> (<i>self</i>, QHostAddress <i>address</i>)</li><li><div class="fn" /><b><a href="qabstractsocket.html#setPeerName">setPeerName</a></b> (<i>self</i>, QString <i>name</i>)</li><li><div class="fn" /><b><a href="qabstractsocket.html#setPeerPort">setPeerPort</a></b> (<i>self</i>, int <i>port</i>)</li><li><div class="fn" /><b><a href="qabstractsocket.html#setProxy">setProxy</a></b> (<i>self</i>, QNetworkProxy <i>networkProxy</i>)</li><li><div class="fn" /><b><a href="qabstractsocket.html#setReadBufferSize">setReadBufferSize</a></b> (<i>self</i>, int <i>size</i>)</li><li><div class="fn" />bool <b><a href="qabstractsocket.html#setSocketDescriptor">setSocketDescriptor</a></b> (<i>self</i>, int <i>socketDescriptor</i>, SocketState <i>state</i> = QAbstractSocket.ConnectedState, QIODevice.OpenMode <i>mode</i> = QIODevice.ReadWrite)</li><li><div class="fn" /><b><a href="qabstractsocket.html#setSocketError">setSocketError</a></b> (<i>self</i>, SocketError <i>socketError</i>)</li><li><div class="fn" /><b><a href="qabstractsocket.html#setSocketOption">setSocketOption</a></b> (<i>self</i>, SocketOption <i>option</i>, QVariant <i>value</i>)</li><li><div class="fn" /><b><a href="qabstractsocket.html#setSocketState">setSocketState</a></b> (<i>self</i>, SocketState <i>state</i>)</li><li><div class="fn" />int <b><a href="qabstractsocket.html#socketDescriptor">socketDescriptor</a></b> (<i>self</i>)</li><li><div class="fn" />QVariant <b><a href="qabstractsocket.html#socketOption">socketOption</a></b> (<i>self</i>, SocketOption <i>option</i>)</li><li><div class="fn" />SocketType <b><a href="qabstractsocket.html#socketType">socketType</a></b> (<i>self</i>)</li><li><div class="fn" />SocketState <b><a href="qabstractsocket.html#state">state</a></b> (<i>self</i>)</li><li><div class="fn" />bool <b><a href="qabstractsocket.html#waitForBytesWritten">waitForBytesWritten</a></b> (<i>self</i>, int <i>msecs</i> = 30000)</li><li><div class="fn" />bool <b><a href="qabstractsocket.html#waitForConnected">waitForConnected</a></b> (<i>self</i>, int <i>msecs</i> = 30000)</li><li><div class="fn" />bool <b><a href="qabstractsocket.html#waitForDisconnected">waitForDisconnected</a></b> (<i>self</i>, int <i>msecs</i> = 30000)</li><li><div class="fn" />bool <b><a href="qabstractsocket.html#waitForReadyRead">waitForReadyRead</a></b> (<i>self</i>, int <i>msecs</i> = 30000)</li><li><div class="fn" />int <b><a href="qabstractsocket.html#writeData">writeData</a></b> (<i>self</i>, str <i>data</i>)</li></ul><h3>Qt Signals</h3><ul><li><div class="fn" />void <b><a href="qabstractsocket.html#connected">connected</a></b> ()</li><li><div class="fn" />void <b><a href="qabstractsocket.html#disconnected">disconnected</a></b> ()</li><li><div class="fn" />void <b><a href="qabstractsocket.html#error-2">error</a></b> (QAbstractSocket::SocketError)</li><li><div class="fn" />void <b><a href="qabstractsocket.html#hostFound">hostFound</a></b> ()</li><li><div class="fn" />void <b><a href="qabstractsocket.html#proxyAuthenticationRequired">proxyAuthenticationRequired</a></b> (const QNetworkProxy&,QAuthenticator *)</li><li><div class="fn" />void <b><a href="qabstractsocket.html#stateChanged">stateChanged</a></b> (QAbstractSocket::SocketState)</li></ul><a name="details" /><hr /><h2>Detailed Description</h2><p>The QAbstractSocket class provides the base functionality common
13
to all socket types.</p>
14
<p>QAbstractSocket is the base class for <a href="qtcpsocket.html">QTcpSocket</a> and <a href="qudpsocket.html">QUdpSocket</a> and contains all common
15
functionality of these two classes. If you need a socket, you have
18
<li>Instantiate <a href="qtcpsocket.html">QTcpSocket</a> or
19
<a href="qudpsocket.html">QUdpSocket</a>.</li>
20
<li>Create a native socket descriptor, instantiate QAbstractSocket,
21
and call <a href="qabstractsocket.html#setSocketDescriptor">setSocketDescriptor</a>()
22
to wrap the native socket.</li>
24
<p>TCP (Transmission Control Protocol) is a reliable,
25
stream-oriented, connection-oriented transport protocol. UDP (User
26
Datagram Protocol) is an unreliable, datagram-oriented,
27
connectionless protocol. In practice, this means that TCP is better
28
suited for continuous transmission of data, whereas the more
29
lightweight UDP can be used when reliability isn't important.</p>
30
<p>QAbstractSocket's API unifies most of the differences between
31
the two protocols. For example, although UDP is connectionless,
32
<a href="qabstractsocket.html#connectToHost">connectToHost</a>()
33
establishes a virtual connection for UDP sockets, enabling you to
34
use QAbstractSocket in more or less the same way regardless of the
35
underlying protocol. Internally, QAbstractSocket remembers the
36
address and port passed to <a href="qabstractsocket.html#connectToHost">connectToHost</a>(), and
37
functions like <a href="qiodevice.html#read">read</a>() and
38
<a href="qiodevice.html#write">write</a>() use these values.</p>
39
<p>At any time, QAbstractSocket has a state (returned by <a href="qabstractsocket.html#state">state</a>()). The initial state is
40
<a href="qabstractsocket.html#SocketState-enum">UnconnectedState</a>. After
41
calling <a href="qabstractsocket.html#connectToHost">connectToHost</a>(), the
42
socket first enters <a href="qabstractsocket.html#SocketState-enum">HostLookupState</a>. If the
43
host is found, QAbstractSocket enters <a href="qabstractsocket.html#SocketState-enum">ConnectingState</a> and
44
emits the <a href="qabstractsocket.html#hostFound">hostFound</a>()
45
signal. When the connection has been established, it enters
46
<a href="qabstractsocket.html#SocketState-enum">ConnectedState</a>
47
and emits <a href="qabstractsocket.html#connected">connected</a>().
48
If an error occurs at any stage, <a href="qabstractsocket.html#error">error</a>() is emitted. Whenever the
49
state changes, <a href="qabstractsocket.html#stateChanged">stateChanged</a>() is emitted.
50
For convenience, <a href="qabstractsocket.html#isValid">isValid</a>() returns true if the
51
socket is ready for reading and writing, but note that the socket's
52
state must be <a href="qabstractsocket.html#SocketState-enum">ConnectedState</a> before
53
reading and writing can occur.</p>
54
<p>Read or write data by calling <a href="qiodevice.html#read">read</a>() or <a href="qiodevice.html#write">write</a>(), or use the convenience
55
functions <a href="qiodevice.html#readLine">readLine</a>() and
56
<a href="qiodevice.html#readAll">readAll</a>(). QAbstractSocket
57
also inherits <a href="qiodevice.html#getChar">getChar</a>(),
58
<a href="qiodevice.html#putChar">putChar</a>(), and <a href="qiodevice.html#ungetChar">ungetChar</a>() from <a href="qiodevice.html">QIODevice</a>, which work on single bytes. The
59
<a href="qiodevice.html#bytesWritten">bytesWritten</a>() signal is
60
emitted when data has been written to the socket (i.e., when the
61
client has read the data). Note that Qt does not limit the write
62
buffer size. You can monitor its size by listening to this
64
<p>The <a href="qiodevice.html#readyRead">readyRead</a>() signal is
65
emitted every time a new chunk of data has arrived. <a href="qabstractsocket.html#bytesAvailable">bytesAvailable</a>() then
66
returns the number of bytes that are available for reading.
67
Typically, you would connect the <a href="qiodevice.html#readyRead">readyRead</a>() signal to a slot and
68
read all available data there. If you don't read all the data at
69
once, the remaining data will still be available later, and any new
70
incoming data will be appended to QAbstractSocket's internal read
71
buffer. To limit the size of the read buffer, call <a href="qabstractsocket.html#setReadBufferSize">setReadBufferSize</a>().</p>
72
<p>To close the socket, call <a href="qabstractsocket.html#disconnectFromHost">disconnectFromHost</a>().
73
QAbstractSocket enters <a href="qabstractsocket.html#SocketState-enum">QAbstractSocket.ClosingState</a>.
74
After all pending data has been written to the socket,
75
QAbstractSocket actually closes the socket, enters
76
QAbstractSocket.ClosedState, and emits <a href="qabstractsocket.html#disconnected">disconnected</a>(). If you want
77
to abort a connection immediately, discarding all pending data,
78
call <a href="qabstractsocket.html#abort">abort</a>() instead. If
79
the remote host closes the connection, QAbstractSocket will emit
80
error(<a href="qabstractsocket.html#SocketError-enum">QAbstractSocket.RemoteHostClosedError</a>),
81
during which the socket state will still be <a href="qabstractsocket.html#SocketState-enum">ConnectedState</a>, and
82
then the <a href="qabstractsocket.html#disconnected">disconnected</a>() signal will
84
<p>The port and address of the connected peer is fetched by calling
85
<a href="qabstractsocket.html#peerPort">peerPort</a>() and <a href="qabstractsocket.html#peerAddress">peerAddress</a>(). <a href="qabstractsocket.html#peerName">peerName</a>() returns the host
86
name of the peer, as passed to <a href="qabstractsocket.html#connectToHost">connectToHost</a>(). <a href="qabstractsocket.html#localPort">localPort</a>() and <a href="qabstractsocket.html#localAddress">localAddress</a>() return the
87
port and address of the local socket.</p>
88
<p>QAbstractSocket provides a set of functions that suspend the
89
calling thread until certain signals are emitted. These functions
90
can be used to implement blocking sockets:</p>
92
<li><a href="qabstractsocket.html#waitForConnected">waitForConnected</a>()
93
blocks until a connection has been established.</li>
94
<li><a href="qabstractsocket.html#waitForReadyRead">waitForReadyRead</a>()
95
blocks until new data is available for reading.</li>
96
<li><a href="qabstractsocket.html#waitForBytesWritten">waitForBytesWritten</a>()
97
blocks until one payload of data has been written to the
99
<li><a href="qabstractsocket.html#waitForDisconnected">waitForDisconnected</a>()
100
blocks until the connection has closed.</li>
102
<p>We show an example:</p>
104
<span class="type">int</span> numRead <span class="operator">=</span> <span class="number">0</span><span class="operator">,</span> numReadTotal <span class="operator">=</span> <span class="number">0</span>;
105
<span class="type">char</span> buffer<span class="operator">[</span><span class="number">50</span><span class="operator">]</span>;
108
numRead <span class="operator">=</span> socket<span class="operator">.</span>read(buffer<span class="operator">,</span> <span class="number">50</span>);
110
<span class="comment">// do whatever with array</span>
112
numReadTotal <span class="operator">+</span><span class="operator">=</span> numRead;
113
<span class="keyword">if</span> (numRead <span class="operator">=</span><span class="operator">=</span> <span class="number">0</span> <span class="operator">&</span><span class="operator">&</span> <span class="operator">!</span>socket<span class="operator">.</span>waitForReadyRead())
114
<span class="keyword">break</span>;
117
<p>If <a href="qiodevice.html#waitForReadyRead">waitForReadyRead()</a> returns
118
false, the connection has been closed or an error has occurred.</p>
119
<p>Programming with a blocking socket is radically different from
120
programming with a non-blocking socket. A blocking socket doesn't
121
require an event loop and typically leads to simpler code. However,
122
in a GUI application, blocking sockets should only be used in
123
non-GUI threads, to avoid freezing the user interface. See the
124
<a href="network-fortuneclient.html">network/fortuneclient</a> and
125
<a href="network-blockingfortuneclient.html">network/blockingfortuneclient</a>
126
examples for an overview of both approaches.</p>
127
<p><b>Note:</b> We discourage the use of the blocking functions
128
together with signals. One of the two possibilities should be
130
<p>QAbstractSocket can be used with <a href="qtextstream.html">QTextStream</a> and <a href="qdatastream.html">QDataStream</a>'s stream operators
131
(operator<<() and operator>>()). There is one issue to
132
be aware of, though: You must make sure that enough data is
133
available before attempting to read it using
134
operator>>().</p>
135
<hr /><h2>Type Documentation</h2><h3 class="fn"><a name="NetworkLayerProtocol-enum" />QAbstractSocket.NetworkLayerProtocol</h3><p>This enum describes the network layer protocol values used in
137
<table class="valuelist">
138
<tr class="odd" valign="top">
139
<th class="tblConst">Constant</th>
140
<th class="tblval">Value</th>
141
<th class="tbldscr">Description</th>
144
<td class="topAlign"><tt>QAbstractSocket.IPv4Protocol</tt></td>
145
<td class="topAlign"><tt>0</tt></td>
146
<td class="topAlign">IPv4</td>
149
<td class="topAlign"><tt>QAbstractSocket.IPv6Protocol</tt></td>
150
<td class="topAlign"><tt>1</tt></td>
151
<td class="topAlign">IPv6</td>
154
<td class="topAlign">
155
<tt>QAbstractSocket.UnknownNetworkLayerProtocol</tt></td>
156
<td class="topAlign"><tt>-1</tt></td>
157
<td class="topAlign">Other than IPv4 and IPv6</td>
160
<p><b>See also</b> <a href="qhostaddress.html#protocol">QHostAddress.protocol</a>().</p>
163
<h3 class="fn"><a name="SocketError-enum" />QAbstractSocket.SocketError</h3><p>This enum describes the socket errors that can occur.</p>
164
<table class="valuelist">
165
<tr class="odd" valign="top">
166
<th class="tblConst">Constant</th>
167
<th class="tblval">Value</th>
168
<th class="tbldscr">Description</th>
171
<td class="topAlign">
172
<tt>QAbstractSocket.ConnectionRefusedError</tt></td>
173
<td class="topAlign"><tt>0</tt></td>
174
<td class="topAlign">The connection was refused by the peer (or
178
<td class="topAlign">
179
<tt>QAbstractSocket.RemoteHostClosedError</tt></td>
180
<td class="topAlign"><tt>1</tt></td>
181
<td class="topAlign">The remote host closed the connection. Note
182
that the client socket (i.e., this socket) will be closed after the
183
remote close notification has been sent.</td>
186
<td class="topAlign">
187
<tt>QAbstractSocket.HostNotFoundError</tt></td>
188
<td class="topAlign"><tt>2</tt></td>
189
<td class="topAlign">The host address was not found.</td>
192
<td class="topAlign">
193
<tt>QAbstractSocket.SocketAccessError</tt></td>
194
<td class="topAlign"><tt>3</tt></td>
195
<td class="topAlign">The socket operation failed because the
196
application lacked the required privileges.</td>
199
<td class="topAlign">
200
<tt>QAbstractSocket.SocketResourceError</tt></td>
201
<td class="topAlign"><tt>4</tt></td>
202
<td class="topAlign">The local system ran out of resources (e.g.,
203
too many sockets).</td>
206
<td class="topAlign">
207
<tt>QAbstractSocket.SocketTimeoutError</tt></td>
208
<td class="topAlign"><tt>5</tt></td>
209
<td class="topAlign">The socket operation timed out.</td>
212
<td class="topAlign">
213
<tt>QAbstractSocket.DatagramTooLargeError</tt></td>
214
<td class="topAlign"><tt>6</tt></td>
215
<td class="topAlign">The datagram was larger than the operating
216
system's limit (which can be as low as 8192 bytes).</td>
219
<td class="topAlign"><tt>QAbstractSocket.NetworkError</tt></td>
220
<td class="topAlign"><tt>7</tt></td>
221
<td class="topAlign">An error occurred with the network (e.g., the
222
network cable was accidentally plugged out).</td>
225
<td class="topAlign">
226
<tt>QAbstractSocket.AddressInUseError</tt></td>
227
<td class="topAlign"><tt>8</tt></td>
228
<td class="topAlign">The address specified to <a href="qudpsocket.html#bind">QUdpSocket.bind</a>() is already in use and
229
was set to be exclusive.</td>
232
<td class="topAlign">
233
<tt>QAbstractSocket.SocketAddressNotAvailableError</tt></td>
234
<td class="topAlign"><tt>9</tt></td>
235
<td class="topAlign">The address specified to <a href="qudpsocket.html#bind">QUdpSocket.bind</a>() does not belong to
239
<td class="topAlign">
240
<tt>QAbstractSocket.UnsupportedSocketOperationError</tt></td>
241
<td class="topAlign"><tt>10</tt></td>
242
<td class="topAlign">The requested socket operation is not
243
supported by the local operating system (e.g., lack of IPv6
247
<td class="topAlign">
248
<tt>QAbstractSocket.ProxyAuthenticationRequiredError</tt></td>
249
<td class="topAlign"><tt>12</tt></td>
250
<td class="topAlign">The socket is using a proxy, and the proxy
251
requires authentication.</td>
254
<td class="topAlign">
255
<tt>QAbstractSocket.SslHandshakeFailedError</tt></td>
256
<td class="topAlign"><tt>13</tt></td>
257
<td class="topAlign">The SSL/TLS handshake failed, so the
258
connection was closed (only used in <a href="qsslsocket.html">QSslSocket</a>) (This value was introduced in
262
<td class="topAlign">
263
<tt>QAbstractSocket.UnfinishedSocketOperationError</tt></td>
264
<td class="topAlign"><tt>11</tt></td>
265
<td class="topAlign">Used by QAbstractSocketEngine only, The last
266
operation attempted has not finished yet (still in progress in the
267
background). (This value was introduced in 4.4.)</td>
270
<td class="topAlign">
271
<tt>QAbstractSocket.ProxyConnectionRefusedError</tt></td>
272
<td class="topAlign"><tt>14</tt></td>
273
<td class="topAlign">Could not contact the proxy server because the
274
connection to that server was denied (This value was introduced in
278
<td class="topAlign">
279
<tt>QAbstractSocket.ProxyConnectionClosedError</tt></td>
280
<td class="topAlign"><tt>15</tt></td>
281
<td class="topAlign">The connection to the proxy server was closed
282
unexpectedly (before the connection to the final peer was
283
established) (This value was introduced in 4.5.)</td>
286
<td class="topAlign">
287
<tt>QAbstractSocket.ProxyConnectionTimeoutError</tt></td>
288
<td class="topAlign"><tt>16</tt></td>
289
<td class="topAlign">The connection to the proxy server timed out
290
or the proxy server stopped responding in the authentication phase.
291
(This value was introduced in 4.5.)</td>
294
<td class="topAlign">
295
<tt>QAbstractSocket.ProxyNotFoundError</tt></td>
296
<td class="topAlign"><tt>17</tt></td>
297
<td class="topAlign">The proxy address set with <a href="qabstractsocket.html#setProxy">setProxy</a>() (or the application
298
proxy) was not found. (This value was introduced in 4.5.)</td>
301
<td class="topAlign">
302
<tt>QAbstractSocket.ProxyProtocolError</tt></td>
303
<td class="topAlign"><tt>18</tt></td>
304
<td class="topAlign">The connection negotiation with the proxy
305
server because the response from the proxy server could not be
306
understood. (This value was introduced in 4.5.)</td>
309
<td class="topAlign">
310
<tt>QAbstractSocket.UnknownSocketError</tt></td>
311
<td class="topAlign"><tt>-1</tt></td>
312
<td class="topAlign">An unidentified error occurred.</td>
315
<p><b>See also</b> <a href="qabstractsocket.html#error">QAbstractSocket.error</a>().</p>
318
<h3 class="fn"><a name="SocketOption-enum" />QAbstractSocket.SocketOption</h3><p>This enum represents the options that can be set on a socket. If
319
desired, they can be set after having received the <a href="qabstractsocket.html#connected">connected</a>() signal from the
320
socket or after having received a new socket from a <a href="qtcpserver.html">QTcpServer</a>.</p>
321
<table class="valuelist">
322
<tr class="odd" valign="top">
323
<th class="tblConst">Constant</th>
324
<th class="tblval">Value</th>
325
<th class="tbldscr">Description</th>
328
<td class="topAlign"><tt>QAbstractSocket.LowDelayOption</tt></td>
329
<td class="topAlign"><tt>0</tt></td>
330
<td class="topAlign">Try to optimize the socket for low latency.
331
For a <a href="qtcpsocket.html">QTcpSocket</a> this would set the
332
TCP_NODELAY option and disable Nagle's algorithm. Set this to 1 to
336
<td class="topAlign"><tt>QAbstractSocket.KeepAliveOption</tt></td>
337
<td class="topAlign"><tt>1</tt></td>
338
<td class="topAlign">Set this to 1 to enable the SO_KEEPALIVE
342
<td class="topAlign">
343
<tt>QAbstractSocket.MulticastTtlOption</tt></td>
344
<td class="topAlign"><tt>2</tt></td>
345
<td class="topAlign">Set this to an integer value to set
346
IP_MULTICAST_TTL (TTL for multicast datagrams) socket option.</td>
349
<td class="topAlign">
350
<tt>QAbstractSocket.MulticastLoopbackOption</tt></td>
351
<td class="topAlign"><tt>3</tt></td>
352
<td class="topAlign">Set this to 1 to enable the IP_MULTICAST_LOOP
353
(multicast loopback) socket option.</td>
356
<p>This enum was introduced or modified in Qt 4.6.</p>
357
<p><b>See also</b> <a href="qabstractsocket.html#setSocketOption">QAbstractSocket.setSocketOption</a>()
358
and <a href="qabstractsocket.html#socketOption">QAbstractSocket.socketOption</a>().</p>
361
<h3 class="fn"><a name="SocketState-enum" />QAbstractSocket.SocketState</h3><p>This enum describes the different states in which a socket can
363
<table class="valuelist">
364
<tr class="odd" valign="top">
365
<th class="tblConst">Constant</th>
366
<th class="tblval">Value</th>
367
<th class="tbldscr">Description</th>
370
<td class="topAlign">
371
<tt>QAbstractSocket.UnconnectedState</tt></td>
372
<td class="topAlign"><tt>0</tt></td>
373
<td class="topAlign">The socket is not connected.</td>
376
<td class="topAlign"><tt>QAbstractSocket.HostLookupState</tt></td>
377
<td class="topAlign"><tt>1</tt></td>
378
<td class="topAlign">The socket is performing a host name
382
<td class="topAlign"><tt>QAbstractSocket.ConnectingState</tt></td>
383
<td class="topAlign"><tt>2</tt></td>
384
<td class="topAlign">The socket has started establishing a
388
<td class="topAlign"><tt>QAbstractSocket.ConnectedState</tt></td>
389
<td class="topAlign"><tt>3</tt></td>
390
<td class="topAlign">A connection is established.</td>
393
<td class="topAlign"><tt>QAbstractSocket.BoundState</tt></td>
394
<td class="topAlign"><tt>4</tt></td>
395
<td class="topAlign">The socket is bound to an address and port
399
<td class="topAlign"><tt>QAbstractSocket.ClosingState</tt></td>
400
<td class="topAlign"><tt>6</tt></td>
401
<td class="topAlign">The socket is about to close (data may still
402
be waiting to be written).</td>
405
<td class="topAlign"><tt>QAbstractSocket.ListeningState</tt></td>
406
<td class="topAlign"><tt>5</tt></td>
407
<td class="topAlign">For internal use only.</td>
410
<p><b>See also</b> <a href="qabstractsocket.html#state">QAbstractSocket.state</a>().</p>
413
<h3 class="fn"><a name="SocketType-enum" />QAbstractSocket.SocketType</h3><p>This enum describes the transport layer protocol.</p>
414
<table class="valuelist">
415
<tr class="odd" valign="top">
416
<th class="tblConst">Constant</th>
417
<th class="tblval">Value</th>
418
<th class="tbldscr">Description</th>
421
<td class="topAlign"><tt>QAbstractSocket.TcpSocket</tt></td>
422
<td class="topAlign"><tt>0</tt></td>
423
<td class="topAlign">TCP</td>
426
<td class="topAlign"><tt>QAbstractSocket.UdpSocket</tt></td>
427
<td class="topAlign"><tt>1</tt></td>
428
<td class="topAlign">UDP</td>
431
<td class="topAlign">
432
<tt>QAbstractSocket.UnknownSocketType</tt></td>
433
<td class="topAlign"><tt>-1</tt></td>
434
<td class="topAlign">Other than TCP and UDP</td>
437
<p><b>See also</b> <a href="qabstractsocket.html#socketType">QAbstractSocket.socketType</a>().</p>
438
<hr /><h2>Method Documentation</h2><h3 class="fn"><a name="QAbstractSocket" />QAbstractSocket.__init__ (<i>self</i>, <a href="qabstractsocket.html#SocketType-enum">SocketType</a> <i>socketType</i>, <a href="qobject.html">QObject</a> <i>parent</i>)</h3><p>The <i>parent</i> argument, if not None, causes <i>self</i> to be owned by Qt instead of PyQt.</p><p>Creates a new abstract socket of type <i>socketType</i>. The
439
<i>parent</i> argument is passed to <a href="qobject.html">QObject</a>'s constructor.</p>
440
<p><b>See also</b> <a href="qabstractsocket.html#socketType">socketType</a>(), <a href="qtcpsocket.html">QTcpSocket</a>, and <a href="qudpsocket.html">QUdpSocket</a>.</p>
443
<h3 class="fn"><a name="abort" />QAbstractSocket.abort (<i>self</i>)</h3><p>Aborts the current connection and resets the socket. Unlike
444
<a href="qabstractsocket.html#disconnectFromHost">disconnectFromHost</a>(),
445
this function immediately closes the socket, discarding any pending
446
data in the write buffer.</p>
447
<p><b>See also</b> <a href="qabstractsocket.html#disconnectFromHost">disconnectFromHost</a>()
448
and <a href="qabstractsocket.html#close">close</a>().</p>
451
<h3 class="fn"><a name="atEnd" />bool QAbstractSocket.atEnd (<i>self</i>)</h3><p>Reimplemented from <a href="qiodevice.html#atEnd">QIODevice.atEnd</a>().</p>
452
<p>Returns true if no more data is currently available for reading;
453
otherwise returns false.</p>
454
<p>This function is most commonly used when reading data from the
455
socket in a loop. For example:</p>
457
<span class="comment">// This slot is connected to QAbstractSocket.readyRead()</span>
458
<span class="type">void</span> SocketClass<span class="operator">.</span>readyReadSlot()
460
<span class="keyword">while</span> (<span class="operator">!</span>socket<span class="operator">.</span>atEnd()) {
461
<span class="type"><a href="qbytearray.html">QByteArray</a></span> data <span class="operator">=</span> socket<span class="operator">.</span>read(<span class="number">100</span>);
462
<span class="operator">.</span><span class="operator">.</span><span class="operator">.</span><span class="operator">.</span>
466
<p><b>See also</b> <a href="qabstractsocket.html#bytesAvailable">bytesAvailable</a>() and
467
<a href="qiodevice.html#readyRead">readyRead</a>().</p>
470
<h3 class="fn"><a name="bytesAvailable" />int QAbstractSocket.bytesAvailable (<i>self</i>)</h3><p>Reimplemented from <a href="qiodevice.html#bytesAvailable">QIODevice.bytesAvailable</a>().</p>
471
<p>Returns the number of incoming bytes that are waiting to be
473
<p><b>See also</b> <a href="qabstractsocket.html#bytesToWrite">bytesToWrite</a>() and <a href="qiodevice.html#read">read</a>().</p>
476
<h3 class="fn"><a name="bytesToWrite" />int QAbstractSocket.bytesToWrite (<i>self</i>)</h3><p>Reimplemented from <a href="qiodevice.html#bytesToWrite">QIODevice.bytesToWrite</a>().</p>
477
<p>Returns the number of bytes that are waiting to be written. The
478
bytes are written when control goes back to the event loop or when
479
<a href="qabstractsocket.html#flush">flush</a>() is called.</p>
480
<p><b>See also</b> <a href="qabstractsocket.html#bytesAvailable">bytesAvailable</a>() and
481
<a href="qabstractsocket.html#flush">flush</a>().</p>
484
<h3 class="fn"><a name="canReadLine" />bool QAbstractSocket.canReadLine (<i>self</i>)</h3><p>Reimplemented from <a href="qiodevice.html#canReadLine">QIODevice.canReadLine</a>().</p>
485
<p>Returns true if a line of data can be read from the socket;
486
otherwise returns false.</p>
487
<p><b>See also</b> <a href="qiodevice.html#readLine">readLine</a>().</p>
490
<h3 class="fn"><a name="close" />QAbstractSocket.close (<i>self</i>)</h3><p>Reimplemented from <a href="qiodevice.html#close">QIODevice.close</a>().</p>
491
<p>Closes the I/O device for the socket, disconnects the socket's
492
connection with the host, closes the socket, and resets the name,
493
address, port number and underlying socket descriptor.</p>
494
<p>See <a href="qiodevice.html#close">QIODevice.close</a>() for a
495
description of the actions that occur when an I/O device is
497
<p><b>See also</b> <a href="qabstractsocket.html#abort">abort</a>().</p>
500
<h3 class="fn"><a name="connectToHost" />QAbstractSocket.connectToHost (<i>self</i>, QString <i>hostName</i>, int <i>port</i>, <a href="qiodevice-openmode.html">QIODevice.OpenMode</a> <i>mode</i> = QIODevice.ReadWrite)</h3><p>Attempts to make a connection to <i>hostName</i> on the given
502
<p>The socket is opened in the given <i>openMode</i> and first
503
enters <a href="qabstractsocket.html#SocketState-enum">HostLookupState</a>, then
504
performs a host name lookup of <i>hostName</i>. If the lookup
505
succeeds, <a href="qabstractsocket.html#hostFound">hostFound</a>()
506
is emitted and <a href="qabstractsocket.html">QAbstractSocket</a>
507
enters <a href="qabstractsocket.html#SocketState-enum">ConnectingState</a>. It
508
then attempts to connect to the address or addresses returned by
509
the lookup. Finally, if a connection is established, <a href="qabstractsocket.html">QAbstractSocket</a> enters <a href="qabstractsocket.html#SocketState-enum">ConnectedState</a> and
510
emits <a href="qabstractsocket.html#connected">connected</a>().</p>
511
<p>At any point, the socket can emit <a href="qabstractsocket.html#error">error</a>() to signal that an error
513
<p><i>hostName</i> may be an IP address in string form (e.g.,
514
"43.195.83.32"), or it may be a host name (e.g., "example.com").
515
<a href="qabstractsocket.html">QAbstractSocket</a> will do a lookup
516
only if required. <i>port</i> is in native byte order.</p>
517
<p><b>See also</b> <a href="qabstractsocket.html#state">state</a>(), <a href="qabstractsocket.html#peerName">peerName</a>(), <a href="qabstractsocket.html#peerAddress">peerAddress</a>(), <a href="qabstractsocket.html#peerPort">peerPort</a>(), and <a href="qabstractsocket.html#waitForConnected">waitForConnected</a>().</p>
520
<h3 class="fn"><a name="connectToHost-2" />QAbstractSocket.connectToHost (<i>self</i>, <a href="qhostaddress.html">QHostAddress</a> <i>address</i>, int <i>port</i>, <a href="qiodevice-openmode.html">QIODevice.OpenMode</a> <i>mode</i> = QIODevice.ReadWrite)</h3><p>This is an overloaded function.</p>
521
<p>Attempts to make a connection to <i>address</i> on port
525
<h3 class="fn"><a name="connectToHostImplementation" />QAbstractSocket.connectToHostImplementation (<i>self</i>, QString <i>hostName</i>, int <i>port</i>, <a href="qiodevice-openmode.html">QIODevice.OpenMode</a> <i>mode</i> = QIODevice.ReadWrite)</h3><p>This method is also a Qt slot with the C++ signature <tt>void connectToHostImplementation(const QString&,quint16,QIODevice::OpenMode = QIODevice.ReadWrite)</tt>.</p><p>Contains the implementation of <a href="qabstractsocket.html#connectToHost">connectToHost</a>().</p>
526
<p>Attempts to make a connection to <i>hostName</i> on the given
527
<i>port</i>. The socket is opened in the given <i>openMode</i>.</p>
528
<p>This function was introduced in Qt 4.1.</p>
531
<h3 class="fn"><a name="disconnectFromHost" />QAbstractSocket.disconnectFromHost (<i>self</i>)</h3><p>Attempts to close the socket. If there is pending data waiting
532
to be written, <a href="qabstractsocket.html">QAbstractSocket</a>
533
will enter <a href="qabstractsocket.html#SocketState-enum">ClosingState</a> and wait
534
until all data has been written. Eventually, it will enter <a href="qabstractsocket.html#SocketState-enum">UnconnectedState</a> and
535
emit the <a href="qabstractsocket.html#disconnected">disconnected</a>() signal.</p>
536
<p><b>See also</b> <a href="qabstractsocket.html#connectToHost">connectToHost</a>().</p>
539
<h3 class="fn"><a name="disconnectFromHostImplementation" />QAbstractSocket.disconnectFromHostImplementation (<i>self</i>)</h3><p>This method is also a Qt slot with the C++ signature <tt>void disconnectFromHostImplementation()</tt>.</p><p>Contains the implementation of <a href="qabstractsocket.html#disconnectFromHost">disconnectFromHost</a>().</p>
540
<p>This function was introduced in Qt 4.1.</p>
543
<h3 class="fn"><a name="error" /><a href="qabstractsocket.html#SocketError-enum">SocketError</a> QAbstractSocket.error (<i>self</i>)</h3><p>Returns the type of error that last occurred.</p>
544
<p><b>See also</b> <a href="qabstractsocket.html#state">state</a>()
545
and <a href="qiodevice.html#errorString">errorString</a>().</p>
548
<h3 class="fn"><a name="flush" />bool QAbstractSocket.flush (<i>self</i>)</h3><p>This function writes as much as possible from the internal write
549
buffer to the underlying network socket, without blocking. If any
550
data was written, this function returns true; otherwise false is
552
<p>Call this function if you need <a href="qabstractsocket.html">QAbstractSocket</a> to start sending
553
buffered data immediately. The number of bytes successfully written
554
depends on the operating system. In most cases, you do not need to
555
call this function, because <a href="qabstractsocket.html">QAbstractSocket</a> will start sending data
556
automatically once control goes back to the event loop. In the
557
absence of an event loop, call <a href="qabstractsocket.html#waitForBytesWritten">waitForBytesWritten</a>()
559
<p><b>See also</b> <a href="qiodevice.html#write">write</a>() and
560
<a href="qabstractsocket.html#waitForBytesWritten">waitForBytesWritten</a>().</p>
563
<h3 class="fn"><a name="isSequential" />bool QAbstractSocket.isSequential (<i>self</i>)</h3><p>Reimplemented from <a href="qiodevice.html#isSequential">QIODevice.isSequential</a>().</p>
566
<h3 class="fn"><a name="isValid" />bool QAbstractSocket.isValid (<i>self</i>)</h3><p>Returns true if the socket is valid and ready for use; otherwise
568
<p><b>Note:</b> The socket's state must be <a href="qabstractsocket.html#SocketState-enum">ConnectedState</a> before
569
reading and writing can occur.</p>
570
<p><b>See also</b> <a href="qabstractsocket.html#state">state</a>().</p>
573
<h3 class="fn"><a name="localAddress" /><a href="qhostaddress.html">QHostAddress</a> QAbstractSocket.localAddress (<i>self</i>)</h3><p>Returns the host address of the local socket if available;
574
otherwise returns <a href="qhostaddress.html#SpecialAddress-enum">QHostAddress.Null</a>.</p>
575
<p>This is normally the main IP address of the host, but can be
576
<a href="qhostaddress.html#SpecialAddress-enum">QHostAddress.LocalHost</a>
577
(127.0.0.1) for connections to the local host.</p>
578
<p><b>See also</b> <a href="qabstractsocket.html#localPort">localPort</a>(), <a href="qabstractsocket.html#peerAddress">peerAddress</a>(), and <a href="qabstractsocket.html#setLocalAddress">setLocalAddress</a>().</p>
581
<h3 class="fn"><a name="localPort" />int QAbstractSocket.localPort (<i>self</i>)</h3><p>Returns the host port number (in native byte order) of the local
582
socket if available; otherwise returns 0.</p>
583
<p><b>See also</b> <a href="qabstractsocket.html#localAddress">localAddress</a>(), <a href="qabstractsocket.html#peerPort">peerPort</a>(), and <a href="qabstractsocket.html#setLocalPort">setLocalPort</a>().</p>
586
<h3 class="fn"><a name="peerAddress" /><a href="qhostaddress.html">QHostAddress</a> QAbstractSocket.peerAddress (<i>self</i>)</h3><p>Returns the address of the connected peer if the socket is in
587
<a href="qabstractsocket.html#SocketState-enum">ConnectedState</a>;
588
otherwise returns <a href="qhostaddress.html#SpecialAddress-enum">QHostAddress.Null</a>.</p>
589
<p><b>See also</b> <a href="qabstractsocket.html#peerName">peerName</a>(), <a href="qabstractsocket.html#peerPort">peerPort</a>(), <a href="qabstractsocket.html#localAddress">localAddress</a>(), and
590
<a href="qabstractsocket.html#setPeerAddress">setPeerAddress</a>().</p>
593
<h3 class="fn"><a name="peerName" />QString QAbstractSocket.peerName (<i>self</i>)</h3><p>Returns the name of the peer as specified by <a href="qabstractsocket.html#connectToHost">connectToHost</a>(), or an
594
empty <a href="qstring.html">QString</a> if <a href="qabstractsocket.html#connectToHost">connectToHost</a>() has not
596
<p><b>See also</b> <a href="qabstractsocket.html#peerAddress">peerAddress</a>(), <a href="qabstractsocket.html#peerPort">peerPort</a>(), and <a href="qabstractsocket.html#setPeerName">setPeerName</a>().</p>
599
<h3 class="fn"><a name="peerPort" />int QAbstractSocket.peerPort (<i>self</i>)</h3><p>Returns the port of the connected peer if the socket is in
600
<a href="qabstractsocket.html#SocketState-enum">ConnectedState</a>;
601
otherwise returns 0.</p>
602
<p><b>See also</b> <a href="qabstractsocket.html#peerAddress">peerAddress</a>(), <a href="qabstractsocket.html#localPort">localPort</a>(), and <a href="qabstractsocket.html#setPeerPort">setPeerPort</a>().</p>
605
<h3 class="fn"><a name="proxy" /><a href="qnetworkproxy.html">QNetworkProxy</a> QAbstractSocket.proxy (<i>self</i>)</h3><p>Returns the network proxy for this socket. By default <a href="qnetworkproxy.html#ProxyType-enum">QNetworkProxy.DefaultProxy</a>
606
is used, which means this socket will query the default proxy
607
settings for the application.</p>
608
<p>This function was introduced in Qt 4.1.</p>
609
<p><b>See also</b> <a href="qabstractsocket.html#setProxy">setProxy</a>(), <a href="qnetworkproxy.html">QNetworkProxy</a>, and <a href="qnetworkproxyfactory.html">QNetworkProxyFactory</a>.</p>
612
<h3 class="fn"><a name="readBufferSize" />int QAbstractSocket.readBufferSize (<i>self</i>)</h3><p>Returns the size of the internal read buffer. This limits the
613
amount of data that the client can receive before you call <a href="qiodevice.html#read">read</a>() or <a href="qiodevice.html#readAll">readAll</a>().</p>
614
<p>A read buffer size of 0 (the default) means that the buffer has
615
no size limit, ensuring that no data is lost.</p>
616
<p><b>See also</b> <a href="qabstractsocket.html#setReadBufferSize">setReadBufferSize</a>()
617
and <a href="qiodevice.html#read">read</a>().</p>
620
<h3 class="fn"><a name="readData" />str QAbstractSocket.readData (<i>self</i>, int <i>maxlen</i>)</h3><p>Reimplemented from <a href="qiodevice.html#readData">QIODevice.readData</a>().</p>
623
<h3 class="fn"><a name="readLineData" />str QAbstractSocket.readLineData (<i>self</i>, int <i>maxlen</i>)</h3><p>Reimplemented from <a href="qiodevice.html#readLineData">QIODevice.readLineData</a>().</p>
626
<h3 class="fn"><a name="setLocalAddress" />QAbstractSocket.setLocalAddress (<i>self</i>, <a href="qhostaddress.html">QHostAddress</a> <i>address</i>)</h3><p>Sets the address on the local side of a connection to
628
<p>You can call this function in a subclass of <a href="qabstractsocket.html">QAbstractSocket</a> to change the return
629
value of the <a href="qabstractsocket.html#localAddress">localAddress</a>() function
630
after a connection has been established. This feature is commonly
631
used by proxy connections for virtual connection settings.</p>
632
<p>Note that this function does not bind the local address of the
633
socket prior to a connection (e.g., <a href="qudpsocket.html#bind">QUdpSocket.bind</a>()).</p>
634
<p>This function was introduced in Qt 4.1.</p>
635
<p><b>See also</b> <a href="qabstractsocket.html#localAddress">localAddress</a>(), <a href="qabstractsocket.html#setLocalPort">setLocalPort</a>(), and
636
<a href="qabstractsocket.html#setPeerAddress">setPeerAddress</a>().</p>
639
<h3 class="fn"><a name="setLocalPort" />QAbstractSocket.setLocalPort (<i>self</i>, int <i>port</i>)</h3><p>Sets the port on the local side of a connection to
641
<p>You can call this function in a subclass of <a href="qabstractsocket.html">QAbstractSocket</a> to change the return
642
value of the <a href="qabstractsocket.html#localPort">localPort</a>() function after a
643
connection has been established. This feature is commonly used by
644
proxy connections for virtual connection settings.</p>
645
<p>Note that this function does not bind the local port of the
646
socket prior to a connection (e.g., <a href="qudpsocket.html#bind">QUdpSocket.bind</a>()).</p>
647
<p>This function was introduced in Qt 4.1.</p>
648
<p><b>See also</b> <a href="qabstractsocket.html#localPort">localPort</a>(), <a href="qabstractsocket.html#localAddress">localAddress</a>(), <a href="qabstractsocket.html#setLocalAddress">setLocalAddress</a>(), and
649
<a href="qabstractsocket.html#setPeerPort">setPeerPort</a>().</p>
652
<h3 class="fn"><a name="setPeerAddress" />QAbstractSocket.setPeerAddress (<i>self</i>, <a href="qhostaddress.html">QHostAddress</a> <i>address</i>)</h3><p>Sets the address of the remote side of the connection to
654
<p>You can call this function in a subclass of <a href="qabstractsocket.html">QAbstractSocket</a> to change the return
655
value of the <a href="qabstractsocket.html#peerAddress">peerAddress</a>() function after
656
a connection has been established. This feature is commonly used by
657
proxy connections for virtual connection settings.</p>
658
<p>This function was introduced in Qt 4.1.</p>
659
<p><b>See also</b> <a href="qabstractsocket.html#peerAddress">peerAddress</a>(), <a href="qabstractsocket.html#setPeerPort">setPeerPort</a>(), and <a href="qabstractsocket.html#setLocalAddress">setLocalAddress</a>().</p>
662
<h3 class="fn"><a name="setPeerName" />QAbstractSocket.setPeerName (<i>self</i>, QString <i>name</i>)</h3><p>Sets the host name of the remote peer to <i>name</i>.</p>
663
<p>You can call this function in a subclass of <a href="qabstractsocket.html">QAbstractSocket</a> to change the return
664
value of the <a href="qabstractsocket.html#peerName">peerName</a>()
665
function after a connection has been established. This feature is
666
commonly used by proxy connections for virtual connection
668
<p>This function was introduced in Qt 4.1.</p>
669
<p><b>See also</b> <a href="qabstractsocket.html#peerName">peerName</a>().</p>
672
<h3 class="fn"><a name="setPeerPort" />QAbstractSocket.setPeerPort (<i>self</i>, int <i>port</i>)</h3><p>Sets the port of the remote side of the connection to
674
<p>You can call this function in a subclass of <a href="qabstractsocket.html">QAbstractSocket</a> to change the return
675
value of the <a href="qabstractsocket.html#peerPort">peerPort</a>()
676
function after a connection has been established. This feature is
677
commonly used by proxy connections for virtual connection
679
<p>This function was introduced in Qt 4.1.</p>
680
<p><b>See also</b> <a href="qabstractsocket.html#peerPort">peerPort</a>(), <a href="qabstractsocket.html#setPeerAddress">setPeerAddress</a>(), and
681
<a href="qabstractsocket.html#setLocalPort">setLocalPort</a>().</p>
684
<h3 class="fn"><a name="setProxy" />QAbstractSocket.setProxy (<i>self</i>, <a href="qnetworkproxy.html">QNetworkProxy</a> <i>networkProxy</i>)</h3><p>Sets the explicit network proxy for this socket to
685
<i>networkProxy</i>.</p>
686
<p>To disable the use of a proxy for this socket, use the <a href="qnetworkproxy.html#ProxyType-enum">QNetworkProxy.NoProxy</a>
689
socket<span class="operator">-</span><span class="operator">></span>setProxy(<span class="type"><a href="qnetworkproxy.html">QNetworkProxy</a></span><span class="operator">.</span>NoProxy);
691
<p>The default value for the proxy is <a href="qnetworkproxy.html#ProxyType-enum">QNetworkProxy.DefaultProxy</a>,
692
which means the socket will use the application settings: if a
693
proxy is set with QNetworkProxy.setApplicationProxy, it will use
694
that; otherwise, if a factory is set with
695
QNetworkProxyFactory.setApplicationProxyFactory, it will query
696
that factory with type <a href="qnetworkproxyquery.html#QueryType-enum">QNetworkProxyQuery.TcpSocket</a>.</p>
697
<p>This function was introduced in Qt 4.1.</p>
698
<p><b>See also</b> <a href="qabstractsocket.html#proxy">proxy</a>(), <a href="qnetworkproxy.html">QNetworkProxy</a>, and <a href="qnetworkproxyfactory.html#queryProxy">QNetworkProxyFactory.queryProxy</a>().</p>
701
<h3 class="fn"><a name="setReadBufferSize" />QAbstractSocket.setReadBufferSize (<i>self</i>, int <i>size</i>)</h3><p>Sets the size of <a href="qabstractsocket.html">QAbstractSocket</a>'s internal read buffer
702
to be <i>size</i> bytes.</p>
703
<p>If the buffer size is limited to a certain size, <a href="qabstractsocket.html">QAbstractSocket</a> won't buffer more than
704
this size of data. Exceptionally, a buffer size of 0 means that the
705
read buffer is unlimited and all incoming data is buffered. This is
707
<p>This option is useful if you only read the data at certain
708
points in time (e.g., in a real-time streaming application) or if
709
you want to protect your socket against receiving too much data,
710
which may eventually cause your application to run out of
712
<p>Only <a href="qtcpsocket.html">QTcpSocket</a> uses <a href="qabstractsocket.html">QAbstractSocket</a>'s internal buffer;
713
<a href="qudpsocket.html">QUdpSocket</a> does not use any buffering
714
at all, but rather relies on the implicit buffering provided by the
715
operating system. Because of this, calling this function on
716
<a href="qudpsocket.html">QUdpSocket</a> has no effect.</p>
717
<p><b>See also</b> <a href="qabstractsocket.html#readBufferSize">readBufferSize</a>() and
718
<a href="qiodevice.html#read">read</a>().</p>
721
<h3 class="fn"><a name="setSocketDescriptor" />bool QAbstractSocket.setSocketDescriptor (<i>self</i>, int <i>socketDescriptor</i>, <a href="qabstractsocket.html#SocketState-enum">SocketState</a> <i>state</i> = QAbstractSocket.ConnectedState, <a href="qiodevice-openmode.html">QIODevice.OpenMode</a> <i>mode</i> = QIODevice.ReadWrite)</h3><p>Initializes <a href="qabstractsocket.html">QAbstractSocket</a>
722
with the native socket descriptor <i>socketDescriptor</i>. Returns
723
true if <i>socketDescriptor</i> is accepted as a valid socket
724
descriptor; otherwise returns false. The socket is opened in the
725
mode specified by <i>openMode</i>, and enters the socket state
726
specified by <i>socketState</i>.</p>
727
<p><b>Note:</b> It is not possible to initialize two abstract
728
sockets with the same native socket descriptor.</p>
729
<p><b>See also</b> <a href="qabstractsocket.html#socketDescriptor">socketDescriptor</a>().</p>
732
<h3 class="fn"><a name="setSocketError" />QAbstractSocket.setSocketError (<i>self</i>, <a href="qabstractsocket.html#SocketError-enum">SocketError</a> <i>socketError</i>)</h3><p>Sets the type of error that last occurred to
733
<i>socketError</i>.</p>
734
<p><b>See also</b> <a href="qabstractsocket.html#setSocketState">setSocketState</a>() and
735
<a href="qiodevice.html#setErrorString">setErrorString</a>().</p>
738
<h3 class="fn"><a name="setSocketOption" />QAbstractSocket.setSocketOption (<i>self</i>, <a href="qabstractsocket.html#SocketOption-enum">SocketOption</a> <i>option</i>, QVariant <i>value</i>)</h3><p>Sets the given <i>option</i> to the value described by
740
<p>This function was introduced in Qt 4.6.</p>
741
<p><b>See also</b> <a href="qabstractsocket.html#socketOption">socketOption</a>().</p>
744
<h3 class="fn"><a name="setSocketState" />QAbstractSocket.setSocketState (<i>self</i>, <a href="qabstractsocket.html#SocketState-enum">SocketState</a> <i>state</i>)</h3><p>Sets the state of the socket to <i>state</i>.</p>
745
<p><b>See also</b> <a href="qabstractsocket.html#state">state</a>().</p>
748
<h3 class="fn"><a name="socketDescriptor" />int QAbstractSocket.socketDescriptor (<i>self</i>)</h3><p>Returns the native socket descriptor of the <a href="qabstractsocket.html">QAbstractSocket</a> object if this is
749
available; otherwise returns -1.</p>
750
<p>If the socket is using <a href="qnetworkproxy.html">QNetworkProxy</a>, the returned descriptor may
751
not be usable with native socket functions.</p>
752
<p>The socket descriptor is not available when <a href="qabstractsocket.html">QAbstractSocket</a> is in <a href="qabstractsocket.html#SocketState-enum">UnconnectedState</a>.</p>
753
<p><b>See also</b> <a href="qabstractsocket.html#setSocketDescriptor">setSocketDescriptor</a>().</p>
756
<h3 class="fn"><a name="socketOption" />QVariant QAbstractSocket.socketOption (<i>self</i>, <a href="qabstractsocket.html#SocketOption-enum">SocketOption</a> <i>option</i>)</h3><p>Returns the value of the <i>option</i> option.</p>
757
<p>This function was introduced in Qt 4.6.</p>
758
<p><b>See also</b> <a href="qabstractsocket.html#setSocketOption">setSocketOption</a>().</p>
761
<h3 class="fn"><a name="socketType" /><a href="qabstractsocket.html#SocketType-enum">SocketType</a> QAbstractSocket.socketType (<i>self</i>)</h3><p>Returns the socket type (TCP, UDP, or other).</p>
762
<p><b>See also</b> <a href="qtcpsocket.html">QTcpSocket</a> and
763
<a href="qudpsocket.html">QUdpSocket</a>.</p>
766
<h3 class="fn"><a name="state" /><a href="qabstractsocket.html#SocketState-enum">SocketState</a> QAbstractSocket.state (<i>self</i>)</h3><p>Returns the state of the socket.</p>
767
<p><b>See also</b> <a href="qabstractsocket.html#error">error</a>().</p>
770
<h3 class="fn"><a name="waitForBytesWritten" />bool QAbstractSocket.waitForBytesWritten (<i>self</i>, int <i>msecs</i> = 30000)</h3><p>Reimplemented from <a href="qiodevice.html#waitForBytesWritten">QIODevice.waitForBytesWritten</a>().</p>
773
<h3 class="fn"><a name="waitForConnected" />bool QAbstractSocket.waitForConnected (<i>self</i>, int <i>msecs</i> = 30000)</h3><p>Waits until the socket is connected, up to <i>msecs</i>
774
milliseconds. If the connection has been established, this function
775
returns true; otherwise it returns false. In the case where it
776
returns false, you can call <a href="qabstractsocket.html#error">error</a>() to determine the cause of
778
<p>The following example waits up to one second for a connection to
781
socket<span class="operator">-</span><span class="operator">></span><a href="qabstractsocket.html#connectToHost">connectToHost</a>(<span class="string">"imap"</span><span class="operator">,</span> <span class="number">143</span>);
782
<span class="keyword">if</span> (socket<span class="operator">-</span><span class="operator">></span>waitForConnected(<span class="number">1000</span>))
783
<a href="qtcore.html#qDebug">qDebug</a>(<span class="string">"Connected!"</span>);
785
<p>If msecs is -1, this function will not time out.</p>
786
<p><b>Note:</b> This function may wait slightly longer than
787
<i>msecs</i>, depending on the time it takes to complete the host
789
<p><b>Note:</b> Multiple calls to this functions do not accumulate
790
the time. If the function times out, the connecting process will be
792
<p><b>See also</b> <a href="qabstractsocket.html#connectToHost">connectToHost</a>() and
793
<a href="qabstractsocket.html#connected">connected</a>().</p>
796
<h3 class="fn"><a name="waitForDisconnected" />bool QAbstractSocket.waitForDisconnected (<i>self</i>, int <i>msecs</i> = 30000)</h3><p>Waits until the socket has disconnected, up to <i>msecs</i>
797
milliseconds. If the connection has been disconnected, this
798
function returns true; otherwise it returns false. In the case
799
where it returns false, you can call <a href="qabstractsocket.html#error">error</a>() to determine the cause of
801
<p>The following example waits up to one second for a connection to
804
socket<span class="operator">-</span><span class="operator">></span><a href="qabstractsocket.html#disconnectFromHost">disconnectFromHost</a>();
805
<span class="keyword">if</span> (socket<span class="operator">-</span><span class="operator">></span>state() <span class="operator">=</span><span class="operator">=</span> <span class="type"><a href="qabstractsocket.html">QAbstractSocket</a></span><span class="operator">.</span>UnconnectedState <span class="operator">|</span><span class="operator">|</span>
806
socket<span class="operator">-</span><span class="operator">></span>waitForDisconnected(<span class="number">1000</span>))
807
<a href="qtcore.html#qDebug">qDebug</a>(<span class="string">"Disconnected!"</span>);
809
<p>If msecs is -1, this function will not time out.</p>
810
<p><b>See also</b> <a href="qabstractsocket.html#disconnectFromHost">disconnectFromHost</a>()
811
and <a href="qabstractsocket.html#close">close</a>().</p>
814
<h3 class="fn"><a name="waitForReadyRead" />bool QAbstractSocket.waitForReadyRead (<i>self</i>, int <i>msecs</i> = 30000)</h3><p>Reimplemented from <a href="qiodevice.html#waitForReadyRead">QIODevice.waitForReadyRead</a>().</p>
815
<p>This function blocks until new data is available for reading and
816
the <a href="qiodevice.html#readyRead">readyRead()</a> signal has
817
been emitted. The function will timeout after <i>msecs</i>
818
milliseconds; the default timeout is 30000 milliseconds.</p>
819
<p>The function returns true if the <a href="qiodevice.html#readyRead">readyRead</a>() signal is emitted and
820
there is new data available for reading; otherwise it returns false
821
(if an error occurred or the operation timed out).</p>
822
<p><b>See also</b> <a href="qabstractsocket.html#waitForBytesWritten">waitForBytesWritten</a>().</p>
825
<h3 class="fn"><a name="writeData" />int QAbstractSocket.writeData (<i>self</i>, str <i>data</i>)</h3><p>Reimplemented from <a href="qiodevice.html#writeData">QIODevice.writeData</a>().</p>
826
<hr /><h2>Qt Signal Documentation</h2><h3 class="fn"><a name="connected" />void connected ()</h3><p>This is the default overload of this signal.</p><p>This signal is emitted after <a href="qabstractsocket.html#connectToHost">connectToHost</a>() has been
827
called and a connection has been successfully established.</p>
828
<p><b>Note:</b> On some operating systems the connected() signal
829
may be directly emitted from the <a href="qabstractsocket.html#connectToHost">connectToHost</a>() call for
830
connections to the localhost.</p>
831
<p><b>See also</b> <a href="qabstractsocket.html#connectToHost">connectToHost</a>() and
832
<a href="qabstractsocket.html#disconnected">disconnected</a>().</p>
835
<h3 class="fn"><a name="disconnected" />void disconnected ()</h3><p>This is the default overload of this signal.</p><p>This signal is emitted when the socket has been
837
<p><b>Warning:</b> If you need to delete the <a href="qobject.html#sender">sender</a>() of this signal in a slot
838
connected to it, use the <a href="qobject.html#deleteLater">deleteLater()</a> function.</p>
839
<p><b>See also</b> <a href="qabstractsocket.html#connectToHost">connectToHost</a>(), <a href="qabstractsocket.html#disconnectFromHost">disconnectFromHost</a>(),
840
and <a href="qabstractsocket.html#abort">abort</a>().</p>
843
<h3 class="fn"><a name="error-2" />void error (QAbstractSocket::SocketError)</h3><p>This is the default overload of this signal.</p><p>This signal is emitted after an error occurred. The
844
<i>socketError</i> parameter describes the type of error that
846
<p><a href="qabstractsocket.html#SocketError-enum">QAbstractSocket.SocketError</a>
847
is not a registered metatype, so for queued connections, you will
848
have to register it with <a href="qmetatype.html#Q_DECLARE_METATYPE">Q_DECLARE_METATYPE</a>() and
849
<a href="qmetatype.html#qRegisterMetaType">qRegisterMetaType</a>().</p>
850
<p><b>See also</b> <a href="qabstractsocket.html#error">error</a>(), <a href="qiodevice.html#errorString">errorString</a>(), and <a href="custom-types.html">Creating Custom Qt Types</a>.</p>
853
<h3 class="fn"><a name="hostFound" />void hostFound ()</h3><p>This is the default overload of this signal.</p><p>This signal is emitted after <a href="qabstractsocket.html#connectToHost">connectToHost</a>() has been
854
called and the host lookup has succeeded.</p>
855
<p><b>Note:</b> Since Qt 4.6.3 <a href="qabstractsocket.html">QAbstractSocket</a> may emit hostFound()
856
directly from the <a href="qabstractsocket.html#connectToHost">connectToHost</a>() call since
857
a DNS result could have been cached.</p>
858
<p><b>See also</b> <a href="qabstractsocket.html#connected">connected</a>().</p>
861
<h3 class="fn"><a name="proxyAuthenticationRequired" />void proxyAuthenticationRequired (const QNetworkProxy&,QAuthenticator *)</h3><p>This is the default overload of this signal.</p><p>This signal can be emitted when a <i>proxy</i> that requires
862
authentication is used. The <i>authenticator</i> object can then be
863
filled in with the required details to allow authentication and
864
continue the connection.</p>
865
<p><b>Note:</b> It is not possible to use a QueuedConnection to
866
connect to this signal, as the connection will fail if the
867
authenticator has not been filled in with new information when the
869
<p>This function was introduced in Qt 4.3.</p>
870
<p><b>See also</b> <a href="qauthenticator.html">QAuthenticator</a>
871
and <a href="qnetworkproxy.html">QNetworkProxy</a>.</p>
874
<h3 class="fn"><a name="stateChanged" />void stateChanged (QAbstractSocket::SocketState)</h3><p>This is the default overload of this signal.</p><p>This signal is emitted whenever <a href="qabstractsocket.html">QAbstractSocket</a>'s state changes. The
875
<i>socketState</i> parameter is the new state.</p>
876
<p><a href="qabstractsocket.html#SocketState-enum">QAbstractSocket.SocketState</a>
877
is not a registered metatype, so for queued connections, you will
878
have to register it with Q_REGISTER_METATYPE() and <a href="qmetatype.html#qRegisterMetaType">qRegisterMetaType</a>().</p>
879
<p><b>See also</b> <a href="qabstractsocket.html#state">state</a>()
880
and <a href="custom-types.html">Creating Custom Qt Types</a>.</p>
883
<address><hr /><div align="center"><table border="0" cellspacing="0" width="100%"><tr class="address"><td align="left" width="25%">PyQt 4.10.3 for X11</td><td align="center" width="50%">Copyright © <a href="http://www.riverbankcomputing.com">Riverbank Computing Ltd</a> and <a href="http://www.qtsoftware.com">Nokia</a> 2012</td><td align="right" width="25%">Qt 4.8.5</td></tr></table></div></address></body></html>
b'\\ No newline at end of file'