~oif-team/ubuntu/natty/qt4-x11/xi2.1

« back to all changes in this revision

Viewing changes to doc/html/qabstractsocket.html

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2005-08-24 04:09:09 UTC
  • Revision ID: james.westby@ubuntu.com-20050824040909-xmxe9jfr4a0w5671
Tags: upstream-4.0.0
ImportĀ upstreamĀ versionĀ 4.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?xml version="1.0" encoding="iso-8859-1"?>
 
2
<!DOCTYPE html
 
3
    PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
 
4
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
 
5
<!-- /tmp/qt-4.0.0-espenr-1119621036935/qt-x11-opensource-desktop-4.0.0/src/network/qabstractsocket.cpp -->
 
6
<head>
 
7
    <title>Qt 4.0: QAbstractSocket Class Reference</title>
 
8
    <style>h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm; }
 
9
a:link { color: #004faf; text-decoration: none }
 
10
a:visited { color: #672967; text-decoration: none }
 
11
td.postheader { font-family: sans-serif }
 
12
tr.address { font-family: sans-serif }
 
13
body { background: #ffffff; color: black; }</style>
 
14
</head>
 
15
<body>
 
16
<table border="0" cellpadding="0" cellspacing="0" width="100%">
 
17
<tr>
 
18
<td align="left" valign="top" width="32"><img src="images/qt-logo.png" align="left" width="32" height="32" border="0" /></td>
 
19
<td width="1">&nbsp;&nbsp;</td><td class="postheader" valign="center"><a href="index.html"><font color="#004faf">Home</font></a>&nbsp;&middot; <a href="classes.html"><font color="#004faf">All&nbsp;Classes</font></a>&nbsp;&middot; <a href="mainclasses.html"><font color="#004faf">Main&nbsp;Classes</font></a>&nbsp;&middot; <a href="annotated.html"><font color="#004faf">Annotated</font></a>&nbsp;&middot; <a href="groups.html"><font color="#004faf">Grouped&nbsp;Classes</font></a>&nbsp;&middot; <a href="functions.html"><font color="#004faf">Functions</font></a></td>
 
20
<td align="right" valign="top" width="230"><img src="images/trolltech-logo.png" align="right" width="203" height="32" border="0" /></td></tr></table><h1 align="center">QAbstractSocket Class Reference</h1>
 
21
<p>The QAbstractSocket class provides the base functionality common to all socket types. <a href="#details">More...</a></p>
 
22
<pre>#include &lt;QAbstractSocket&gt;</pre><p>Part of the <a href="qtnetwork.html">QtNetwork</a> module.</p>
 
23
<p>Inherits <a href="qiodevice.html">QIODevice</a>.</p>
 
24
<p>Inherited by <a href="qtcpsocket.html">QTcpSocket</a> and <a href="qudpsocket.html">QUdpSocket</a>.</p>
 
25
<p><b>Note:</b> All the functions in this class are <a href="threads.html#reentrant">reentrant</a>.</p>
 
26
<ul>
 
27
<li><a href="qabstractsocket-members.html">List of all members, including inherited members</a></li>
 
28
<li><a href="qabstractsocket-qt3.html">Qt 3 support members</a></li>
 
29
</ul>
 
30
<a name="public-types"></a>
 
31
<h3>Public Types</h3>
 
32
<ul>
 
33
<li><div class="fn"/>enum <b><a href="qabstractsocket.html#SocketError-enum">SocketError</a></b> { ConnectionRefusedError, RemoteHostClosedError, HostNotFoundError, SocketAccessError, ..., UnknownSocketError }</li>
 
34
<li><div class="fn"/>enum <b><a href="qabstractsocket.html#SocketState-enum">SocketState</a></b> { UnconnectedState, HostLookupState, ConnectingState, ConnectedState, ..., ListeningState }</li>
 
35
<li><div class="fn"/>enum <b><a href="qabstractsocket.html#SocketType-enum">SocketType</a></b> { TcpSocket, UdpSocket, UnknownSocketType }</li>
 
36
</ul>
 
37
<a name="public-functions"></a>
 
38
<h3>Public Functions</h3>
 
39
<ul>
 
40
<li><div class="fn"/><b><a href="qabstractsocket.html#QAbstractSocket">QAbstractSocket</a></b> ( SocketType <i>socketType</i>, QObject * <i>parent</i> )</li>
 
41
<li><div class="fn"/>virtual <b><a href="qabstractsocket.html#dtor.QAbstractSocket">~QAbstractSocket</a></b> ()</li>
 
42
<li><div class="fn"/>void <b><a href="qabstractsocket.html#abort">abort</a></b> ()</li>
 
43
<li><div class="fn"/>virtual qint64 <b><a href="qabstractsocket.html#bytesAvailable">bytesAvailable</a></b> () const</li>
 
44
<li><div class="fn"/>virtual qint64 <b><a href="qabstractsocket.html#bytesToWrite">bytesToWrite</a></b> () const</li>
 
45
<li><div class="fn"/>virtual bool <b><a href="qabstractsocket.html#canReadLine">canReadLine</a></b> () const</li>
 
46
<li><div class="fn"/>virtual void <b><a href="qabstractsocket.html#close">close</a></b> ()</li>
 
47
<li><div class="fn"/>void <b><a href="qabstractsocket.html#connectToHost">connectToHost</a></b> ( const QString &amp; <i>hostName</i>, quint16 <i>port</i>, OpenMode <i>openMode</i> = ReadWrite )</li>
 
48
<li><div class="fn"/>void <b><a href="qabstractsocket.html#connectToHost-2">connectToHost</a></b> ( const QHostAddress &amp; <i>address</i>, quint16 <i>port</i>, OpenMode <i>openMode</i> = ReadWrite )</li>
 
49
<li><div class="fn"/>void <b><a href="qabstractsocket.html#disconnectFromHost">disconnectFromHost</a></b> ()</li>
 
50
<li><div class="fn"/>SocketError <b><a href="qabstractsocket.html#error">error</a></b> () const</li>
 
51
<li><div class="fn"/>bool <b><a href="qabstractsocket.html#flush">flush</a></b> ()</li>
 
52
<li><div class="fn"/>bool <b><a href="qabstractsocket.html#isValid">isValid</a></b> () const</li>
 
53
<li><div class="fn"/>QHostAddress <b><a href="qabstractsocket.html#localAddress">localAddress</a></b> () const</li>
 
54
<li><div class="fn"/>quint16 <b><a href="qabstractsocket.html#localPort">localPort</a></b> () const</li>
 
55
<li><div class="fn"/>QHostAddress <b><a href="qabstractsocket.html#peerAddress">peerAddress</a></b> () const</li>
 
56
<li><div class="fn"/>QString <b><a href="qabstractsocket.html#peerName">peerName</a></b> () const</li>
 
57
<li><div class="fn"/>quint16 <b><a href="qabstractsocket.html#peerPort">peerPort</a></b> () const</li>
 
58
<li><div class="fn"/>qint64 <b><a href="qabstractsocket.html#readBufferSize">readBufferSize</a></b> () const</li>
 
59
<li><div class="fn"/>void <b><a href="qabstractsocket.html#setReadBufferSize">setReadBufferSize</a></b> ( qint64 <i>size</i> )</li>
 
60
<li><div class="fn"/>bool <b><a href="qabstractsocket.html#setSocketDescriptor">setSocketDescriptor</a></b> ( int <i>socketDescriptor</i>, SocketState <i>socketState</i> = ConnectedState, OpenMode <i>openMode</i> = ReadWrite )</li>
 
61
<li><div class="fn"/>int <b><a href="qabstractsocket.html#socketDescriptor">socketDescriptor</a></b> () const</li>
 
62
<li><div class="fn"/>SocketType <b><a href="qabstractsocket.html#socketType">socketType</a></b> () const</li>
 
63
<li><div class="fn"/>SocketState <b><a href="qabstractsocket.html#state">state</a></b> () const</li>
 
64
<li><div class="fn"/>bool <b><a href="qabstractsocket.html#waitForConnected">waitForConnected</a></b> ( int <i>msecs</i> = 30000 )</li>
 
65
<li><div class="fn"/>bool <b><a href="qabstractsocket.html#waitForDisconnected">waitForDisconnected</a></b> ( int <i>msecs</i> = 30000 )</li>
 
66
</ul>
 
67
<ul>
 
68
<li><div class="fn"/>30 public functions inherited from <a href="qiodevice.html#public-functions">QIODevice</a></li>
 
69
<li><div class="fn"/>28 public functions inherited from <a href="qobject.html#public-functions">QObject</a></li>
 
70
</ul>
 
71
<a name="signals"></a>
 
72
<h3>Signals</h3>
 
73
<ul>
 
74
<li><div class="fn"/>void <b><a href="qabstractsocket.html#connected">connected</a></b> ()</li>
 
75
<li><div class="fn"/>void <b><a href="qabstractsocket.html#disconnected">disconnected</a></b> ()</li>
 
76
<li><div class="fn"/>void <b><a href="qabstractsocket.html#error-2">error</a></b> ( SocketError <i>socketError</i> )</li>
 
77
<li><div class="fn"/>void <b><a href="qabstractsocket.html#hostFound">hostFound</a></b> ()</li>
 
78
<li><div class="fn"/>void <b><a href="qabstractsocket.html#stateChanged">stateChanged</a></b> ( SocketState <i>socketState</i> )</li>
 
79
</ul>
 
80
<ul>
 
81
<li><div class="fn"/>3 signals inherited from <a href="qiodevice.html#signals">QIODevice</a></li>
 
82
<li><div class="fn"/>1 signal inherited from <a href="qobject.html#signals">QObject</a></li>
 
83
</ul>
 
84
<a name="protected-functions"></a>
 
85
<h3>Protected Functions</h3>
 
86
<ul>
 
87
<li><div class="fn"/>void <b><a href="qabstractsocket.html#setSocketError">setSocketError</a></b> ( SocketError <i>socketError</i> )</li>
 
88
<li><div class="fn"/>void <b><a href="qabstractsocket.html#setSocketState">setSocketState</a></b> ( SocketState <i>state</i> )</li>
 
89
</ul>
 
90
<ul>
 
91
<li><div class="fn"/>5 protected functions inherited from <a href="qiodevice.html#protected-functions">QIODevice</a></li>
 
92
<li><div class="fn"/>7 protected functions inherited from <a href="qobject.html#protected-functions">QObject</a></li>
 
93
</ul>
 
94
<h3>Additional Inherited Members</h3>
 
95
<ul>
 
96
<li><div class="fn"/>1 property inherited from <a href="qobject.html#properties">QObject</a></li>
 
97
<li><div class="fn"/>1 public slot inherited from <a href="qobject.html#public-slots">QObject</a></li>
 
98
<li><div class="fn"/>4 static public members inherited from <a href="qobject.html#static-public-members">QObject</a></li>
 
99
</ul>
 
100
<a name="details"></a>
 
101
<hr />
 
102
<h2>Detailed Description</h2>
 
103
<p>The QAbstractSocket class provides the base functionality common to all socket types.</p>
 
104
<p>QAbstractSocket is the base class for <a href="qtcpsocket.html">QTcpSocket</a> and <a href="qudpsocket.html">QUdpSocket</a> and contains all common functionality of these two classes. If you need a socket, you have two options:</p>
 
105
<ul>
 
106
<li>Instantiate <a href="qtcpsocket.html">QTcpSocket</a> or <a href="qudpsocket.html">QUdpSocket</a>.</li>
 
107
<li>Create a native socket descriptor, instantiate QAbstractSocket, and call <a href="qabstractsocket.html#setSocketDescriptor">setSocketDescriptor</a>() to wrap the native socket.</li>
 
108
</ul>
 
109
<p>TCP (Transmission Control Protocol) is a reliable, stream-oriented, connection-oriented transport protocol. UDP (User Datagram Protocol) is an unreliable, datagram-oriented, connectionless protocol. In practice, this means that TCP is better suited for continuous transmission of data, whereas the more lightweight UDP can be used when reliability isn't important.</p>
 
110
<p>QAbstractSocket's API unifies most of the differences between the two protocols. For example, although UDP is connectionless, <a href="qabstractsocket.html#connectToHost">connectToHost</a>() establishes a virtual connection for UDP sockets, enabling you to use QAbstractSocket in more or less the same way regardless of the underlying protocol. Internally, QAbstractSocket remembers the address and port passed to <a href="qabstractsocket.html#connectToHost">connectToHost</a>(), and functions like <a href="qiodevice.html#read">read</a>() and <a href="qiodevice.html#write">write</a>() use these values.</p>
 
111
<p>At any time, QAbstractSocket has a state (returned by <a href="qabstractsocket.html#state">state</a>()). The initial state is <a href="qabstractsocket.html#SocketState-enum">QAbstractSocket::UnconnectedState</a>. After calling <a href="qabstractsocket.html#connectToHost">connectToHost</a>(), the socket first enters <a href="qabstractsocket.html#SocketState-enum">QAbstractSocket::HostLookupState</a>. If the host is found, QAbstractSocket enters <a href="qabstractsocket.html#SocketState-enum">QAbstractSocket::ConnectingState</a> and emits the <a href="qabstractsocket.html#hostFound">hostFound</a>() signal. When the connection has been established, it enters <a href="qabstractsocket.html#SocketState-enum">QAbstractSocket::ConnectedState</a> and emits <a href="qabstractsocket.html#connected">connected</a>(). If an error occurs at any stage, <a href="qabstractsocket.html#error">error</a>() is emitted. Whenever the state changes, <a href="qabstractsocket.html#stateChanged">stateChanged</a>() is emitted. For convenience, <a href="qabstractsocket.html#isValid">isValid</a>() returns true if the socket is ready for reading and writing.</p>
 
112
<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 functions <a href="qiodevice.html#readLine">readLine</a>() and <a href="qiodevice.html#readAll">readAll</a>(). QAbstractSocket also inherits <a href="qiodevice.html#getChar">getChar</a>(), <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. For every chunk of data that has been written to the socket, the <a href="qiodevice.html#bytesWritten">bytesWritten</a>() signal is emitted.</p>
 
113
<p>The <a href="qiodevice.html#readyRead">readyRead</a>() signal is emitted every time a new chunk of data has arrived. <a href="qabstractsocket.html#bytesAvailable">bytesAvailable</a>() then returns the number of bytes that are available for reading. Typically, you would connect the <a href="qiodevice.html#readyRead">readyRead</a>() signal to a slot and read all available data there. If you don't read all the data at once, the remaining data will still be available later, and any new incoming data will be appended to QAbstractSocket's internal read buffer. To limit the size of the read buffer, call <a href="qabstractsocket.html#setReadBufferSize">setReadBufferSize</a>().</p>
 
114
<p>To close the socket, call <a href="qabstractsocket.html#close">close</a>(). QAbstractSocket enters <a href="qabstractsocket.html#SocketState-enum">QAbstractSocket::ClosingState</a>, then emits closing(). After all pending data has been written to the socket, QAbstractSocket actually closes the socket, enters QAbstractSocket::ClosedState, and emits closed(). If you want to abort a connection immediately, discarding all pending data, call <a href="qabstractsocket.html#abort">abort</a>() instead.</p>
 
115
<p>The port and address of the connected peer is fetched by calling <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 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 port and address of the local socket.</p>
 
116
<p>QAbstractSocket provides a set of functions that suspend the calling thread until certain signals are emitted. These functions can be used to implement blocking sockets:</p>
 
117
<ul>
 
118
<li><a href="qabstractsocket.html#waitForConnected">waitForConnected</a>() blocks until a connection has been established.</li>
 
119
<li><a href="qabstractsocket.html#waitForReadyRead">waitForReadyRead</a>() blocks until new data is available for reading.</li>
 
120
<li><a href="qabstractsocket.html#waitForBytesWritten">waitForBytesWritten</a>() blocks until one payload of data has been written to the socket.</li>
 
121
<li>waitForClosed() blocks until the connection has closed.</li>
 
122
</ul>
 
123
<p>Programming with a blocking socket is radically different from programming with a non-blocking socket. A blocking socket doesn't require an event loop and typically leads to simpler code. However, in a GUI application, blocking sockets should only be used in non-GUI threads, to avoid freezing the user interface. See the <a href="network-fortuneclient.html">network/fortuneclient</a> and <a href="network-blockingfortuneclient.html">network/blockingfortuneclient</a> examples for an overview of both approaches.</p>
 
124
<p>QAbstractSocket can be used with <a href="qtextstream.html">QTextStream</a> and <a href="qdatastream.html">QDataStream</a>'s stream operators (operator&lt;&lt;() and operator&gt;&gt;()). There is one issue to be aware of, though: You must make sure that enough data is available before attempting to read it using operator&gt;&gt;().</p>
 
125
<p>See also <a href="qftp.html">QFtp</a>, <a href="qhttp.html">QHttp</a>, and <a href="qtcpserver.html">QTcpServer</a>.</p>
 
126
<hr />
 
127
<h2>Member Type Documentation</h2>
 
128
<h3 class="fn"><a name="SocketError-enum"></a>enum QAbstractSocket::SocketError</h3>
 
129
<p>This enum describes the socket errors that can occur.</p>
 
130
<table border="1" cellpadding="2" cellspacing="1" width="100%">
 
131
<tr><th width="25%">Constant</th><th width="15%">Value</th><th width="60%">Description</th></tr>
 
132
<tr><td valign="top"><tt>QAbstractSocket::ConnectionRefusedError</tt></td><td align="center" valign="top"><tt>0</tt></td><td valign="top">The connection was refused by the peer (or timed out).</td></tr>
 
133
<tr><td valign="top"><tt>QAbstractSocket::RemoteHostClosedError</tt></td><td align="center" valign="top"><tt>1</tt></td><td valign="top">The remote host closed the connection.</td></tr>
 
134
<tr><td valign="top"><tt>QAbstractSocket::HostNotFoundError</tt></td><td align="center" valign="top"><tt>2</tt></td><td valign="top">The host address was not found.</td></tr>
 
135
<tr><td valign="top"><tt>QAbstractSocket::SocketAccessError</tt></td><td align="center" valign="top"><tt>3</tt></td><td valign="top">The socket operation failed because the application lacked the required privileges.</td></tr>
 
136
<tr><td valign="top"><tt>QAbstractSocket::SocketResourceError</tt></td><td align="center" valign="top"><tt>4</tt></td><td valign="top">The local system ran out of resources (e.g., too many sockets).</td></tr>
 
137
<tr><td valign="top"><tt>QAbstractSocket::SocketTimeoutError</tt></td><td align="center" valign="top"><tt>5</tt></td><td valign="top">The socket operation timed out.</td></tr>
 
138
<tr><td valign="top"><tt>QAbstractSocket::DatagramTooLargeError</tt></td><td align="center" valign="top"><tt>6</tt></td><td valign="top">The datagram was larger than the operating system's limit (which can be as low as 8192 bytes).</td></tr>
 
139
<tr><td valign="top"><tt>QAbstractSocket::NetworkError</tt></td><td align="center" valign="top"><tt>7</tt></td><td valign="top">An error occurred with the network (e.g., the network cable was accidentally plugged out).</td></tr>
 
140
<tr><td valign="top"><tt>QAbstractSocket::AddressInUseError</tt></td><td align="center" valign="top"><tt>8</tt></td><td valign="top">The address specified to <a href="qudpsocket.html#bind">QUdpSocket::bind</a>() is already in use and was set to be exclusive.</td></tr>
 
141
<tr><td valign="top"><tt>QAbstractSocket::SocketAddressNotAvailableError</tt></td><td align="center" valign="top"><tt>9</tt></td><td valign="top">The address specified to <a href="qudpsocket.html#bind">QUdpSocket::bind</a>() does not belong to the host.</td></tr>
 
142
<tr><td valign="top"><tt>QAbstractSocket::UnsupportedSocketOperationError</tt></td><td align="center" valign="top"><tt>10</tt></td><td valign="top">The requested socket operation is not supported by the local operating system (e.g., lack of IPv6 support).</td></tr>
 
143
<tr><td valign="top"><tt>QAbstractSocket::UnknownSocketError</tt></td><td align="center" valign="top"><tt>-1</tt></td><td valign="top">An unidentified error occurred.</td></tr>
 
144
</table>
 
145
<p>See also <a href="qabstractsocket.html#error">QAbstractSocket::error</a>().</p>
 
146
<h3 class="fn"><a name="SocketState-enum"></a>enum QAbstractSocket::SocketState</h3>
 
147
<p>This enum describes the different states in which a socket can be.</p>
 
148
<table border="1" cellpadding="2" cellspacing="1" width="100%">
 
149
<tr><th width="25%">Constant</th><th width="15%">Value</th><th width="60%">Description</th></tr>
 
150
<tr><td valign="top"><tt>QAbstractSocket::UnconnectedState</tt></td><td align="center" valign="top"><tt>0</tt></td><td valign="top">The socket is not connected.</td></tr>
 
151
<tr><td valign="top"><tt>QAbstractSocket::HostLookupState</tt></td><td align="center" valign="top"><tt>1</tt></td><td valign="top">The socket is performing a host name lookup.</td></tr>
 
152
<tr><td valign="top"><tt>QAbstractSocket::ConnectingState</tt></td><td align="center" valign="top"><tt>2</tt></td><td valign="top">The socket has started establishing a connection.</td></tr>
 
153
<tr><td valign="top"><tt>QAbstractSocket::ConnectedState</tt></td><td align="center" valign="top"><tt>3</tt></td><td valign="top">A connection is established.</td></tr>
 
154
<tr><td valign="top"><tt>QAbstractSocket::BoundState</tt></td><td align="center" valign="top"><tt>4</tt></td><td valign="top">The socket is bound to an address and port (for servers).</td></tr>
 
155
<tr><td valign="top"><tt>QAbstractSocket::ClosingState</tt></td><td align="center" valign="top"><tt>6</tt></td><td valign="top">The socket is about to close (data may still be waiting to be written).</td></tr>
 
156
<tr><td valign="top"><tt>QAbstractSocket::ListeningState</tt></td><td align="center" valign="top"><tt>5</tt></td><td valign="top">For internal use only.</td></tr>
 
157
</table>
 
158
<p>See also <a href="qabstractsocket.html#state">QAbstractSocket::state</a>().</p>
 
159
<h3 class="fn"><a name="SocketType-enum"></a>enum QAbstractSocket::SocketType</h3>
 
160
<p>This enum describes the transport layer protocol.</p>
 
161
<table border="1" cellpadding="2" cellspacing="1" width="100%">
 
162
<tr><th width="25%">Constant</th><th width="15%">Value</th><th width="60%">Description</th></tr>
 
163
<tr><td valign="top"><tt>QAbstractSocket::TcpSocket</tt></td><td align="center" valign="top"><tt>0</tt></td><td valign="top">TCP</td></tr>
 
164
<tr><td valign="top"><tt>QAbstractSocket::UdpSocket</tt></td><td align="center" valign="top"><tt>1</tt></td><td valign="top">UDP</td></tr>
 
165
<tr><td valign="top"><tt>QAbstractSocket::UnknownSocketType</tt></td><td align="center" valign="top"><tt>-1</tt></td><td valign="top">Other than TCP and UDP</td></tr>
 
166
</table>
 
167
<p>See also <a href="qabstractsocket.html#socketType">QAbstractSocket::socketType</a>().</p>
 
168
<hr />
 
169
<h2>Member Function Documentation</h2>
 
170
<h3 class="fn"><a name="QAbstractSocket"></a>QAbstractSocket::QAbstractSocket ( <a href="qabstractsocket.html#SocketType-enum">SocketType</a> <i>socketType</i>, <a href="qobject.html">QObject</a> * <i>parent</i> )</h3>
 
171
<p>Creates a new abstract socket of type <i>socketType</i>. The <i>parent</i> argument is passed to <a href="qobject.html">QObject</a>'s constructor.</p>
 
172
<p>See also <a href="qabstractsocket.html#socketType">socketType</a>(), <a href="qtcpsocket.html">QTcpSocket</a>, and <a href="qudpsocket.html">QUdpSocket</a>.</p>
 
173
<h3 class="fn"><a name="dtor.QAbstractSocket"></a>QAbstractSocket::~QAbstractSocket ()&nbsp;&nbsp;<tt> [virtual]</tt></h3>
 
174
<p>Destroys the socket.</p>
 
175
<h3 class="fn"><a name="abort"></a>void QAbstractSocket::abort ()</h3>
 
176
<p>Aborts the current connection and resets the socket. Unlike <a href="qabstractsocket.html#close">close</a>(), this function immediately closes the socket, clearing any pending data in the write buffer.</p>
 
177
<p>See also <a href="qabstractsocket.html#close">close</a>().</p>
 
178
<h3 class="fn"><a name="bytesAvailable"></a><a href="qtglobal.html#qint64-typedef">qint64</a> QAbstractSocket::bytesAvailable () const&nbsp;&nbsp;<tt> [virtual]</tt></h3>
 
179
<p>Returns the number of incoming bytes that are waiting to be read.</p>
 
180
<p>Reimplemented from <a href="qiodevice.html#bytesAvailable">QIODevice</a>.</p>
 
181
<p>See also <a href="qabstractsocket.html#bytesToWrite">bytesToWrite</a>() and <a href="qiodevice.html#read">read</a>().</p>
 
182
<h3 class="fn"><a name="bytesToWrite"></a><a href="qtglobal.html#qint64-typedef">qint64</a> QAbstractSocket::bytesToWrite () const&nbsp;&nbsp;<tt> [virtual]</tt></h3>
 
183
<p>Returns the number of bytes that are waiting to be written. The bytes are written when control goes back to the event loop or when <a href="qabstractsocket.html#flush">flush</a>() is called.</p>
 
184
<p>Reimplemented from <a href="qiodevice.html#bytesToWrite">QIODevice</a>.</p>
 
185
<p>See also <a href="qabstractsocket.html#bytesAvailable">bytesAvailable</a>() and <a href="qabstractsocket.html#flush">flush</a>().</p>
 
186
<h3 class="fn"><a name="canReadLine"></a>bool QAbstractSocket::canReadLine () const&nbsp;&nbsp;<tt> [virtual]</tt></h3>
 
187
<p>Returns true if a line of data can be read from the socket; otherwise returns false.</p>
 
188
<p>Reimplemented from <a href="qiodevice.html#canReadLine">QIODevice</a>.</p>
 
189
<p>See also <a href="qiodevice.html#readLine">readLine</a>().</p>
 
190
<h3 class="fn"><a name="close"></a>void QAbstractSocket::close ()&nbsp;&nbsp;<tt> [virtual]</tt></h3>
 
191
<p>Attempts to close the socket. If there is pending data waiting to be written, <a href="qabstractsocket.html">QAbstractSocket</a> will enter <a href="qabstractsocket.html#SocketState-enum">ClosingState</a> and wait until all data has been written. Eventually, it will enter <a href="qabstractsocket.html#SocketState-enum">UnconnectedState</a> and emit the <a href="qabstractsocket.html#disconnected">disconnected</a>() signal.</p>
 
192
<p>Reimplemented from <a href="qiodevice.html#close">QIODevice</a>.</p>
 
193
<p>See also <a href="qabstractsocket.html#abort">abort</a>().</p>
 
194
<h3 class="fn"><a name="connectToHost"></a>void QAbstractSocket::connectToHost ( const <a href="qstring.html">QString</a> &amp; <i>hostName</i>, <a href="qtglobal.html#quint16-typedef">quint16</a> <i>port</i>, <a href="qiodevice.html#OpenModeFlag-enum">OpenMode</a> <i>openMode</i> = ReadWrite )</h3>
 
195
<p>Attempts to make a connection to <i>hostName</i> on the given <i>port</i>.</p>
 
196
<p>The socket is opened in the given <i>openMode</i> and first enters <a href="qabstractsocket.html#SocketState-enum">HostLookupState</a>, then performs a host name lookup of <i>hostName</i>. If the lookup succeeds, <a href="qabstractsocket.html#hostFound">hostFound</a>() is emitted and <a href="qabstractsocket.html">QAbstractSocket</a> enters <a href="qabstractsocket.html#SocketState-enum">ConnectingState</a>. It then attempts to connect to the address or addresses returned by the lookup. Finally, if a connection is established, <a href="qabstractsocket.html">QAbstractSocket</a> enters <a href="qabstractsocket.html#SocketState-enum">ConnectedState</a> and emits <a href="qabstractsocket.html#connected">connected</a>().</p>
 
197
<p>At any point, the socket can emit <a href="qabstractsocket.html#error">error</a>() to signal that an error occurred.</p>
 
198
<p><i>hostName</i> may be an IP address in string form (e.g., &quot;43.195.83.32&quot;), or it may be a host name (e.g., &quot;www.trolltech.com&quot;). <a href="qabstractsocket.html">QAbstractSocket</a> will do a lookup only if required. <i>port</i> is in native byte order.</p>
 
199
<p>See also <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>
 
200
<h3 class="fn"><a name="connectToHost-2"></a>void QAbstractSocket::connectToHost ( const <a href="qhostaddress.html">QHostAddress</a> &amp; <i>address</i>, <a href="qtglobal.html#quint16-typedef">quint16</a> <i>port</i>, <a href="qiodevice.html#OpenModeFlag-enum">OpenMode</a> <i>openMode</i> = ReadWrite )</h3>
 
201
<p>This is an overloaded member function, provided for convenience. It behaves essentially like the above function.</p>
 
202
<p>Attempts to make a connection to <i>address</i> on port <i>port</i>.</p>
 
203
<h3 class="fn"><a name="connected"></a>void QAbstractSocket::connected ()&nbsp;&nbsp;<tt> [signal]</tt></h3>
 
204
<p>This signal is emitted after <a href="qabstractsocket.html#connectToHost">connectToHost</a>() has been called and a connection has been successfully established.</p>
 
205
<p>See also <a href="qabstractsocket.html#connectToHost">connectToHost</a>() and <a href="qabstractsocket-qt3.html#connectionClosed">connectionClosed</a>().</p>
 
206
<h3 class="fn"><a name="disconnectFromHost"></a>void QAbstractSocket::disconnectFromHost ()</h3>
 
207
<p>Disconnects the socket's connection with the host.</p>
 
208
<p>See also <a href="qabstractsocket.html#connectToHost">connectToHost</a>().</p>
 
209
<h3 class="fn"><a name="disconnected"></a>void QAbstractSocket::disconnected ()&nbsp;&nbsp;<tt> [signal]</tt></h3>
 
210
<p>This signal is emitted when the socket has been disconnected.</p>
 
211
<p>See also <a href="qabstractsocket.html#connectToHost">connectToHost</a>() and <a href="qabstractsocket.html#close">close</a>().</p>
 
212
<h3 class="fn"><a name="error"></a><a href="qabstractsocket.html#SocketError-enum">SocketError</a> QAbstractSocket::error () const</h3>
 
213
<p>Returns the type of error that last occurred.</p>
 
214
<p>See also <a href="qabstractsocket.html#state">state</a>() and <a href="qiodevice.html#errorString">errorString</a>().</p>
 
215
<h3 class="fn"><a name="error-2"></a>void QAbstractSocket::error ( <a href="qabstractsocket.html#SocketError-enum">SocketError</a> <i>socketError</i> )&nbsp;&nbsp;<tt> [signal]</tt></h3>
 
216
<p>This is an overloaded member function, provided for convenience. It behaves essentially like the above function.</p>
 
217
<p>This signal is emitted after an error occurred. The <i>socketError</i> parameter describes the type of error that occurred.</p>
 
218
<p>See also <a href="qabstractsocket.html#error">error</a>() and <a href="qiodevice.html#errorString">errorString</a>().</p>
 
219
<h3 class="fn"><a name="flush"></a>bool QAbstractSocket::flush ()</h3>
 
220
<p>This function writes as much as possible from the internal write buffer to the underlying network socket, without blocking. If any data was written, this function returns true; otherwise false is returned.</p>
 
221
<p>Call this function if you need <a href="qabstractsocket.html">QAbstractSocket</a> to start sending buffered data immediately. The number of bytes successfully written depends on the operating system. In most cases, you do not need to call this function, because <a href="qabstractsocket.html">QAbstractSocket</a> will start sending data automatically once control goes back to the event loop. In the absence of an event loop, call <a href="qabstractsocket.html#waitForBytesWritten">waitForBytesWritten</a>() instead.</p>
 
222
<p>See also <a href="qiodevice.html#write">write</a>() and <a href="qabstractsocket.html#waitForBytesWritten">waitForBytesWritten</a>().</p>
 
223
<h3 class="fn"><a name="hostFound"></a>void QAbstractSocket::hostFound ()&nbsp;&nbsp;<tt> [signal]</tt></h3>
 
224
<p>This signal is emitted after <a href="qabstractsocket.html#connectToHost">connectToHost</a>() has been called and the host lookup has succeeded.</p>
 
225
<p>See also <a href="qabstractsocket.html#connected">connected</a>().</p>
 
226
<h3 class="fn"><a name="isValid"></a>bool QAbstractSocket::isValid () const</h3>
 
227
<p>Returns true if the socket is valid and ready for use; otherwise returns false.</p>
 
228
<p>See also <a href="qabstractsocket.html#state">state</a>().</p>
 
229
<h3 class="fn"><a name="localAddress"></a><a href="qhostaddress.html">QHostAddress</a> QAbstractSocket::localAddress () const</h3>
 
230
<p>Returns the host address of the local socket if available; otherwise returns <a href="qhostaddress.html#SpecialAddress-enum">QHostAddress::Null</a>.</p>
 
231
<p>This is normally the main IP address of the host, but can be <a href="qhostaddress.html#SpecialAddress-enum">QHostAddress::LocalHost</a> (127.0.0.1) for connections to the local host.</p>
 
232
<p>See also <a href="qabstractsocket.html#localPort">localPort</a>() and <a href="qabstractsocket.html#peerAddress">peerAddress</a>().</p>
 
233
<h3 class="fn"><a name="localPort"></a><a href="qtglobal.html#quint16-typedef">quint16</a> QAbstractSocket::localPort () const</h3>
 
234
<p>Returns the host port number (in native byte order) of the local socket if available; otherwise returns 0.</p>
 
235
<p>See also <a href="qabstractsocket.html#localAddress">localAddress</a>() and <a href="qabstractsocket.html#peerPort">peerPort</a>().</p>
 
236
<h3 class="fn"><a name="peerAddress"></a><a href="qhostaddress.html">QHostAddress</a> QAbstractSocket::peerAddress () const</h3>
 
237
<p>Returns the address of the connected peer if the socket is in <a href="qabstractsocket.html#SocketState-enum">ConnectedState</a>; otherwise returns <a href="qhostaddress.html#SpecialAddress-enum">QHostAddress::Null</a>.</p>
 
238
<p>See also <a href="qabstractsocket.html#peerName">peerName</a>(), <a href="qabstractsocket.html#peerPort">peerPort</a>(), and <a href="qabstractsocket.html#localAddress">localAddress</a>().</p>
 
239
<h3 class="fn"><a name="peerName"></a><a href="qstring.html">QString</a> QAbstractSocket::peerName () const</h3>
 
240
<p>Returns the name of the peer as specified by <a href="qabstractsocket.html#connectToHost">connectToHost</a>(), or an empty <a href="qstring.html">QString</a> if <a href="qabstractsocket.html#connectToHost">connectToHost</a>() has not been called.</p>
 
241
<p>See also <a href="qabstractsocket.html#peerAddress">peerAddress</a>() and <a href="qabstractsocket.html#peerPort">peerPort</a>().</p>
 
242
<h3 class="fn"><a name="peerPort"></a><a href="qtglobal.html#quint16-typedef">quint16</a> QAbstractSocket::peerPort () const</h3>
 
243
<p>Returns the port of the connected peer if the socket is in <a href="qabstractsocket.html#SocketState-enum">ConnectedState</a>; otherwise returns 0.</p>
 
244
<p>See also <a href="qabstractsocket.html#peerAddress">peerAddress</a>() and <a href="qabstractsocket.html#localPort">localPort</a>().</p>
 
245
<h3 class="fn"><a name="readBufferSize"></a><a href="qtglobal.html#qint64-typedef">qint64</a> QAbstractSocket::readBufferSize () const</h3>
 
246
<p>Returns the size of the internal read buffer. This limits the 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>
 
247
<p>A read buffer size of 0 (the default) means that the buffer has no size limit, ensuring that no data is lost.</p>
 
248
<p>See also <a href="qabstractsocket.html#setReadBufferSize">setReadBufferSize</a>() and <a href="qiodevice.html#read">read</a>().</p>
 
249
<h3 class="fn"><a name="setReadBufferSize"></a>void QAbstractSocket::setReadBufferSize ( <a href="qtglobal.html#qint64-typedef">qint64</a> <i>size</i> )</h3>
 
250
<p>Sets the size of <a href="qabstractsocket.html">QAbstractSocket</a>'s internal read buffer to be <i>size</i> bytes.</p>
 
251
<p>If the buffer size is limited to a certain size, <a href="qabstractsocket.html">QAbstractSocket</a> won't buffer more than this size of data. Exceptionally, a buffer size of 0 means that the read buffer is unlimited and all incoming data is buffered. This is the default.</p>
 
252
<p>This option is useful if you only read the data at certain points in time (e.g., in a real-time streaming application) or if you want to protect your socket against receiving too much data, which may eventually cause your application to run out of memory.</p>
 
253
<p>See also <a href="qabstractsocket.html#readBufferSize">readBufferSize</a>() and <a href="qiodevice.html#read">read</a>().</p>
 
254
<h3 class="fn"><a name="setSocketDescriptor"></a>bool QAbstractSocket::setSocketDescriptor ( int <i>socketDescriptor</i>, <a href="qabstractsocket.html#SocketState-enum">SocketState</a> <i>socketState</i> = ConnectedState, <a href="qiodevice.html#OpenModeFlag-enum">OpenMode</a> <i>openMode</i> = ReadWrite )</h3>
 
255
<p>Initializes <a href="qabstractsocket.html">QAbstractSocket</a> with the native socket descriptor <i>socketDescriptor</i>. Returns true if <i>socketDescriptor</i> is accepted as a valid socket descriptor; otherwise returns false. The socket is opened in the mode specified by <i>openMode</i>, and enters the socket state specified by <i>socketState</i>.</p>
 
256
<p>See also <a href="qabstractsocket.html#socketDescriptor">socketDescriptor</a>().</p>
 
257
<h3 class="fn"><a name="setSocketError"></a>void QAbstractSocket::setSocketError ( <a href="qabstractsocket.html#SocketError-enum">SocketError</a> <i>socketError</i> )&nbsp;&nbsp;<tt> [protected]</tt></h3>
 
258
<p>Sets the type of error that last occurred to <i>socketError</i>.</p>
 
259
<p>See also <a href="qabstractsocket.html#setSocketState">setSocketState</a>() and <a href="qiodevice.html#setErrorString">setErrorString</a>().</p>
 
260
<h3 class="fn"><a name="setSocketState"></a>void QAbstractSocket::setSocketState ( <a href="qabstractsocket.html#SocketState-enum">SocketState</a> <i>state</i> )&nbsp;&nbsp;<tt> [protected]</tt></h3>
 
261
<p>Sets the state of the socket to <i>state</i>.</p>
 
262
<p>See also <a href="qabstractsocket.html#state">state</a>().</p>
 
263
<h3 class="fn"><a name="socketDescriptor"></a>int QAbstractSocket::socketDescriptor () const</h3>
 
264
<p>Returns the native socket descriptor of <a href="qabstractsocket.html">QAbstractSocket</a> if this is available; otherwise returns -1.</p>
 
265
<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>
 
266
<p>See also <a href="qabstractsocket.html#setSocketDescriptor">setSocketDescriptor</a>().</p>
 
267
<h3 class="fn"><a name="socketType"></a><a href="qabstractsocket.html#SocketType-enum">SocketType</a> QAbstractSocket::socketType () const</h3>
 
268
<p>Returns the socket type (TCP, UDP, or other).</p>
 
269
<p>See also <a href="qtcpsocket.html">QTcpSocket</a> and <a href="qudpsocket.html">QUdpSocket</a>.</p>
 
270
<h3 class="fn"><a name="state"></a><a href="qabstractsocket.html#SocketState-enum">SocketState</a> QAbstractSocket::state () const</h3>
 
271
<p>Returns the state of the socket.</p>
 
272
<p>See also <a href="qabstractsocket.html#error">error</a>().</p>
 
273
<h3 class="fn"><a name="stateChanged"></a>void QAbstractSocket::stateChanged ( <a href="qabstractsocket.html#SocketState-enum">SocketState</a> <i>socketState</i> )&nbsp;&nbsp;<tt> [signal]</tt></h3>
 
274
<p>This signal is emitted whenever <a href="qabstractsocket.html">QAbstractSocket</a>'s state changes. The <i>socketState</i> parameter is the new state.</p>
 
275
<p>See also <a href="qabstractsocket.html#state">state</a>().</p>
 
276
<h3 class="fn"><a name="waitForConnected"></a>bool QAbstractSocket::waitForConnected ( int <i>msecs</i> = 30000 )</h3>
 
277
<p>Waits until the socket is connected, up to <i>msecs</i> milliseconds. If the connection has been established, this function returns true; otherwise it returns false. In the case where it returns false, you can call <a href="qabstractsocket.html#error">error</a>() to determine the cause of the error.</p>
 
278
<p>The following example waits up to one second for a connection to be established:</p>
 
279
<pre>&nbsp;   socket-&gt;connectToHost(&quot;imap&quot;, 143);
 
280
    if (socket-&gt;waitForConnected(1000))
 
281
        qDebug(&quot;Connected!&quot;);</pre>
 
282
<p>If msecs is -1, this function will not time out.</p>
 
283
<p>See also <a href="qabstractsocket.html#connectToHost">connectToHost</a>() and <a href="qabstractsocket.html#connected">connected</a>().</p>
 
284
<h3 class="fn"><a name="waitForDisconnected"></a>bool QAbstractSocket::waitForDisconnected ( int <i>msecs</i> = 30000 )</h3>
 
285
<p>Waits until the socket has disconnected, up to <i>msecs</i> milliseconds. If the connection has been disconnected, this function returns true; otherwise it returns false. In the case where it returns false, you can call <a href="qabstractsocket.html#error">error</a>() to determine the cause of the error.</p>
 
286
<p>The following example waits up to one second for a connection to be closed:</p>
 
287
<pre>&nbsp;   socket-&gt;disconnect();
 
288
    if (socket-&gt;waitForDisconnected(1000))
 
289
        qDebug(&quot;Disconnected!&quot;);</pre>
 
290
<p>If msecs is -1, this function will not time out.</p>
 
291
<p>See also <a href="qobject.html#disconnect">disconnect</a>() and <a href="qabstractsocket.html#close">close</a>().</p>
 
292
<p /><address><hr /><div align="center">
 
293
<table width="100%" cellspacing="0" border="0"><tr class="address">
 
294
<td width="30%">Copyright &copy; 2005 <a href="trolltech.html">Trolltech</a></td>
 
295
<td width="40%" align="center"><a href="trademarks.html">Trademarks</a></td>
 
296
<td width="30%" align="right"><div align="right">Qt 4.0.0</div></td>
 
297
</tr></table></div></address></body>
 
298
</html>