Sophie

Sophie

distrib > Mandriva > current > i586 > media > main-updates > by-pkgid > 8e6051afcdb111a0317a58fb64c2abf5 > files > 3642

qt4-doc-4.6.3-0.2mdv2010.2.i586.rpm

<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html
    PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<!-- qabstractsocket.cpp -->
<head>
  <title>Qt 4.6: QAbstractSocket Class Reference</title>
  <link href="classic.css" rel="stylesheet" type="text/css" />
</head>
<body>
<a name="//apple_ref/cpp/cl//QAbstractSocket"></a>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td align="left" valign="top" width="32"><a href="http://qt.nokia.com/"><img src="images/qt-logo.png" align="left" border="0" /></a></td>
<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="functions.html"><font color="#004faf">All&nbsp;Functions</font></a>&nbsp;&middot; <a href="overviews.html"><font color="#004faf">Overviews</font></a></td></tr></table><h1 class="title">QAbstractSocket Class Reference<br /><span class="small-subtitle">[<a href="qtnetwork.html">QtNetwork</a> module]</span>
</h1>
<p>The QAbstractSocket class provides the base functionality common to all socket types. <a href="#details">More...</a></p>
<pre> #include &lt;QAbstractSocket&gt;</pre><p><b>This class is not part of the Qt GUI Framework Edition.</b></p>
<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>
<p><b>Note:</b> All functions in this class are <a href="threads-reentrancy.html#reentrant">reentrant</a>.</p>
<ul>
<li><a href="qabstractsocket-members.html">List of all members, including inherited members</a></li>
<li><a href="qabstractsocket-qt3.html">Qt 3 support members</a></li>
</ul>
<hr />
<a name="public-types"></a>
<h2>Public Types</h2>
<table class="alignedsummary" border="0" cellpadding="0" cellspacing="0" width="100%">
<tr><td class="memItemLeft" align="right" valign="top">enum </td><td class="memItemRight" valign="bottom"><b><a href="qabstractsocket.html#NetworkLayerProtocol-enum">NetworkLayerProtocol</a></b> { IPv4Protocol, IPv6Protocol, UnknownNetworkLayerProtocol }</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">enum </td><td class="memItemRight" valign="bottom"><b><a href="qabstractsocket.html#SocketError-enum">SocketError</a></b> { ConnectionRefusedError, RemoteHostClosedError, HostNotFoundError, SocketAccessError, ..., UnknownSocketError }</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">enum </td><td class="memItemRight" valign="bottom"><b><a href="qabstractsocket.html#SocketOption-enum">SocketOption</a></b> { LowDelayOption, KeepAliveOption }</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">enum </td><td class="memItemRight" valign="bottom"><b><a href="qabstractsocket.html#SocketState-enum">SocketState</a></b> { UnconnectedState, HostLookupState, ConnectingState, ConnectedState, ..., ListeningState }</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">enum </td><td class="memItemRight" valign="bottom"><b><a href="qabstractsocket.html#SocketType-enum">SocketType</a></b> { TcpSocket, UdpSocket, UnknownSocketType }</td></tr>
</table>
<hr />
<a name="public-functions"></a>
<h2>Public Functions</h2>
<table class="alignedsummary" border="0" cellpadding="0" cellspacing="0" width="100%">
<tr><td class="memItemLeft" align="right" valign="top"></td><td class="memItemRight" valign="bottom"><b><a href="qabstractsocket.html#QAbstractSocket">QAbstractSocket</a></b> ( SocketType <i>socketType</i>, QObject * <i>parent</i> )</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">virtual </td><td class="memItemRight" valign="bottom"><b><a href="qabstractsocket.html#dtor.QAbstractSocket">~QAbstractSocket</a></b> ()</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><b><a href="qabstractsocket.html#abort">abort</a></b> ()</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><b><a href="qabstractsocket.html#connectToHost">connectToHost</a></b> ( const QString &amp; <i>hostName</i>, quint16 <i>port</i>, OpenMode <i>openMode</i> = ReadWrite )</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><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 )</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><b><a href="qabstractsocket.html#disconnectFromHost">disconnectFromHost</a></b> ()</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">SocketError </td><td class="memItemRight" valign="bottom"><b><a href="qabstractsocket.html#error">error</a></b> () const</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">bool </td><td class="memItemRight" valign="bottom"><b><a href="qabstractsocket.html#flush">flush</a></b> ()</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">bool </td><td class="memItemRight" valign="bottom"><b><a href="qabstractsocket.html#isValid">isValid</a></b> () const</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">QHostAddress </td><td class="memItemRight" valign="bottom"><b><a href="qabstractsocket.html#localAddress">localAddress</a></b> () const</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">quint16 </td><td class="memItemRight" valign="bottom"><b><a href="qabstractsocket.html#localPort">localPort</a></b> () const</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">QHostAddress </td><td class="memItemRight" valign="bottom"><b><a href="qabstractsocket.html#peerAddress">peerAddress</a></b> () const</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">QString </td><td class="memItemRight" valign="bottom"><b><a href="qabstractsocket.html#peerName">peerName</a></b> () const</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">quint16 </td><td class="memItemRight" valign="bottom"><b><a href="qabstractsocket.html#peerPort">peerPort</a></b> () const</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">QNetworkProxy </td><td class="memItemRight" valign="bottom"><b><a href="qabstractsocket.html#proxy">proxy</a></b> () const</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">qint64 </td><td class="memItemRight" valign="bottom"><b><a href="qabstractsocket.html#readBufferSize">readBufferSize</a></b> () const</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><b><a href="qabstractsocket.html#setProxy">setProxy</a></b> ( const QNetworkProxy &amp; <i>networkProxy</i> )</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><b><a href="qabstractsocket.html#setReadBufferSize">setReadBufferSize</a></b> ( qint64 <i>size</i> )</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">bool </td><td class="memItemRight" valign="bottom"><b><a href="qabstractsocket.html#setSocketDescriptor">setSocketDescriptor</a></b> ( int <i>socketDescriptor</i>, SocketState <i>socketState</i> = ConnectedState, OpenMode <i>openMode</i> = ReadWrite )</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><b><a href="qabstractsocket.html#setSocketOption">setSocketOption</a></b> ( QAbstractSocket::SocketOption <i>option</i>, const QVariant &amp; <i>value</i> )</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">int </td><td class="memItemRight" valign="bottom"><b><a href="qabstractsocket.html#socketDescriptor">socketDescriptor</a></b> () const</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">QVariant </td><td class="memItemRight" valign="bottom"><b><a href="qabstractsocket.html#socketOption">socketOption</a></b> ( QAbstractSocket::SocketOption <i>option</i> )</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">SocketType </td><td class="memItemRight" valign="bottom"><b><a href="qabstractsocket.html#socketType">socketType</a></b> () const</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">SocketState </td><td class="memItemRight" valign="bottom"><b><a href="qabstractsocket.html#state">state</a></b> () const</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">bool </td><td class="memItemRight" valign="bottom"><b><a href="qabstractsocket.html#waitForConnected">waitForConnected</a></b> ( int <i>msecs</i> = 30000 )</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">bool </td><td class="memItemRight" valign="bottom"><b><a href="qabstractsocket.html#waitForDisconnected">waitForDisconnected</a></b> ( int <i>msecs</i> = 30000 )</td></tr>
</table>
<hr />
<a name="reimplemented-public-functions"></a>
<h2>Reimplemented Public Functions</h2>
<table class="alignedsummary" border="0" cellpadding="0" cellspacing="0" width="100%">
<tr><td class="memItemLeft" align="right" valign="top">virtual bool </td><td class="memItemRight" valign="bottom"><b><a href="qabstractsocket.html#atEnd">atEnd</a></b> () const</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">virtual qint64 </td><td class="memItemRight" valign="bottom"><b><a href="qabstractsocket.html#bytesAvailable">bytesAvailable</a></b> () const</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">virtual qint64 </td><td class="memItemRight" valign="bottom"><b><a href="qabstractsocket.html#bytesToWrite">bytesToWrite</a></b> () const</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">virtual bool </td><td class="memItemRight" valign="bottom"><b><a href="qabstractsocket.html#canReadLine">canReadLine</a></b> () const</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">virtual void </td><td class="memItemRight" valign="bottom"><b><a href="qabstractsocket.html#close">close</a></b> ()</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">virtual bool </td><td class="memItemRight" valign="bottom"><b><a href="qabstractsocket.html#isSequential">isSequential</a></b> () const</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">virtual bool </td><td class="memItemRight" valign="bottom"><b><a href="qabstractsocket.html#waitForBytesWritten">waitForBytesWritten</a></b> ( int <i>msecs</i> = 30000 )</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">virtual bool </td><td class="memItemRight" valign="bottom"><b><a href="qabstractsocket.html#waitForReadyRead">waitForReadyRead</a></b> ( int <i>msecs</i> = 30000 )</td></tr>
</table>
<ul>
<li><div bar="2" class="fn"></div>33 public functions inherited from <a href="qiodevice.html#public-functions">QIODevice</a></li>
<li><div bar="2" class="fn"></div>29 public functions inherited from <a href="qobject.html#public-functions">QObject</a></li>
</ul>
<hr />
<a name="signals"></a>
<h2>Signals</h2>
<table class="alignedsummary" border="0" cellpadding="0" cellspacing="0" width="100%">
<tr><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><b><a href="qabstractsocket.html#connected">connected</a></b> ()</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><b><a href="qabstractsocket.html#disconnected">disconnected</a></b> ()</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><b><a href="qabstractsocket.html#error-2">error</a></b> ( QAbstractSocket::SocketError <i>socketError</i> )</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><b><a href="qabstractsocket.html#hostFound">hostFound</a></b> ()</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><b><a href="qabstractsocket.html#proxyAuthenticationRequired">proxyAuthenticationRequired</a></b> ( const QNetworkProxy &amp; <i>proxy</i>, QAuthenticator * <i>authenticator</i> )</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><b><a href="qabstractsocket.html#stateChanged">stateChanged</a></b> ( QAbstractSocket::SocketState <i>socketState</i> )</td></tr>
</table>
<ul>
<li><div bar="2" class="fn"></div>4 signals inherited from <a href="qiodevice.html#signals">QIODevice</a></li>
<li><div bar="2" class="fn"></div>1 signal inherited from <a href="qobject.html#signals">QObject</a></li>
</ul>
<hr />
<a name="protected-functions"></a>
<h2>Protected Functions</h2>
<table class="alignedsummary" border="0" cellpadding="0" cellspacing="0" width="100%">
<tr><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><b><a href="qabstractsocket.html#setLocalAddress">setLocalAddress</a></b> ( const QHostAddress &amp; <i>address</i> )</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><b><a href="qabstractsocket.html#setLocalPort">setLocalPort</a></b> ( quint16 <i>port</i> )</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><b><a href="qabstractsocket.html#setPeerAddress">setPeerAddress</a></b> ( const QHostAddress &amp; <i>address</i> )</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><b><a href="qabstractsocket.html#setPeerName">setPeerName</a></b> ( const QString &amp; <i>name</i> )</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><b><a href="qabstractsocket.html#setPeerPort">setPeerPort</a></b> ( quint16 <i>port</i> )</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><b><a href="qabstractsocket.html#setSocketError">setSocketError</a></b> ( SocketError <i>socketError</i> )</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><b><a href="qabstractsocket.html#setSocketState">setSocketState</a></b> ( SocketState <i>state</i> )</td></tr>
</table>
<hr />
<a name="reimplemented-protected-functions"></a>
<h2>Reimplemented Protected Functions</h2>
<table class="alignedsummary" border="0" cellpadding="0" cellspacing="0" width="100%">
<tr><td class="memItemLeft" align="right" valign="top">virtual qint64 </td><td class="memItemRight" valign="bottom"><b><a href="qabstractsocket.html#readData">readData</a></b> ( char * <i>data</i>, qint64 <i>maxSize</i> )</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">virtual qint64 </td><td class="memItemRight" valign="bottom"><b><a href="qabstractsocket.html#readLineData">readLineData</a></b> ( char * <i>data</i>, qint64 <i>maxlen</i> )</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">virtual qint64 </td><td class="memItemRight" valign="bottom"><b><a href="qabstractsocket.html#writeData">writeData</a></b> ( const char * <i>data</i>, qint64 <i>size</i> )</td></tr>
</table>
<ul>
<li><div bar="2" class="fn"></div>5 protected functions inherited from <a href="qiodevice.html#protected-functions">QIODevice</a></li>
<li><div bar="2" class="fn"></div>7 protected functions inherited from <a href="qobject.html#protected-functions">QObject</a></li>
</ul>
<hr />
<a name="protected-slots"></a>
<h2>Protected Slots</h2>
<table class="alignedsummary" border="0" cellpadding="0" cellspacing="0" width="100%">
<tr><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><b><a href="qabstractsocket.html#connectToHostImplementation">connectToHostImplementation</a></b> ( const QString &amp; <i>hostName</i>, quint16 <i>port</i>, OpenMode <i>openMode</i> = ReadWrite )</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><b><a href="qabstractsocket.html#disconnectFromHostImplementation">disconnectFromHostImplementation</a></b> ()</td></tr>
</table>
<h3>Additional Inherited Members</h3>
<ul>
<li><div class="fn"></div>1 property inherited from <a href="qobject.html#properties">QObject</a></li>
<li><div class="fn"></div>1 public slot inherited from <a href="qobject.html#public-slots">QObject</a></li>
<li><div class="fn"></div>5 static public members inherited from <a href="qobject.html#static-public-members">QObject</a></li>
</ul>
<a name="details"></a>
<hr />
<h2>Detailed Description</h2>
<p>The QAbstractSocket class provides the base functionality common to all socket types.</p>
<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>
<ul>
<li>Instantiate <a href="qtcpsocket.html">QTcpSocket</a> or <a href="qudpsocket.html">QUdpSocket</a>.</li>
<li>Create a native socket descriptor, instantiate QAbstractSocket, and call <a href="qabstractsocket.html#setSocketDescriptor">setSocketDescriptor</a>() to wrap the native socket.</li>
</ul>
<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>
<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>
<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">UnconnectedState</a>. After calling <a href="qabstractsocket.html#connectToHost">connectToHost</a>(), the socket first enters <a href="qabstractsocket.html#SocketState-enum">HostLookupState</a>. If the host is found, QAbstractSocket enters <a href="qabstractsocket.html#SocketState-enum">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">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, but note that the socket's state must be <a href="qabstractsocket.html#SocketState-enum">ConnectedState</a> before reading and writing can occur.</p>
<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. The <a href="qiodevice.html#bytesWritten">bytesWritten</a>() signal is emitted when data has been written to the socket (i.e&#x2e;, when the client has read the data). Note that Qt does not limit the write buffer size. You can monitor its size by listening to this signal.</p>
<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>
<p>To close the socket, call <a href="qabstractsocket.html#disconnectFromHost">disconnectFromHost</a>(). QAbstractSocket enters <a href="qabstractsocket.html#SocketState-enum">QAbstractSocket::ClosingState</a>. After all pending data has been written to the socket, QAbstractSocket actually closes the socket, enters QAbstractSocket::ClosedState, and emits <a href="qabstractsocket.html#disconnected">disconnected</a>(). If you want to abort a connection immediately, discarding all pending data, call <a href="qabstractsocket.html#abort">abort</a>() instead. If the remote host closes the connection, QAbstractSocket will emit error(<a href="qabstractsocket.html#SocketError-enum">QAbstractSocket::RemoteHostClosedError</a>), during which the socket state will still be <a href="qabstractsocket.html#SocketState-enum">ConnectedState</a>, and then the <a href="qabstractsocket.html#disconnected">disconnected</a>() signal will be emitted.</p>
<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>
<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>
<ul>
<li><a href="qabstractsocket.html#waitForConnected">waitForConnected</a>() blocks until a connection has been established.</li>
<li><a href="qabstractsocket.html#waitForReadyRead">waitForReadyRead</a>() blocks until new data is available for reading.</li>
<li><a href="qabstractsocket.html#waitForBytesWritten">waitForBytesWritten</a>() blocks until one payload of data has been written to the socket.</li>
<li><a href="qabstractsocket.html#waitForDisconnected">waitForDisconnected</a>() blocks until the connection has closed.</li>
</ul>
<p>We show an example:</p>
<pre>     int numRead = 0, numReadTotal = 0;
     char buffer[50];

     forever {
         numRead  = socket.read(buffer, 50);

         <span class="comment">// do whatever with array</span>

         numReadTotal += numRead;
         if (numRead == 0 &amp;&amp; !socket.waitForReadyRead())
             break;
     }</pre>
<p>If <a href="qiodevice.html#waitForReadyRead">waitForReadyRead()</a> returns false, the connection has been closed or an error has occurred.</p>
<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>
<p><b>Note:</b> We discourage the use of the blocking functions together with signals. One of the two possibilities should be used.</p>
<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>
<p>See also <a href="qftp.html">QFtp</a>, <a href="qnetworkaccessmanager.html">QNetworkAccessManager</a>, and <a href="qtcpserver.html">QTcpServer</a>.</p>
<hr />
<h2>Member Type Documentation</h2>
<a name="//apple_ref/cpp/tag/QAbstractSocket/NetworkLayerProtocol"></a>
<a name="//apple_ref/cpp/econst/QAbstractSocket/IPv4Protocol"></a>
<a name="//apple_ref/cpp/econst/QAbstractSocket/IPv6Protocol"></a>
<a name="//apple_ref/cpp/econst/QAbstractSocket/UnknownNetworkLayerProtocol"></a>
<h3 class="fn"><a name="NetworkLayerProtocol-enum"></a>enum QAbstractSocket::NetworkLayerProtocol</h3>
<p>This enum describes the network layer protocol values used in Qt.</p>
<p><table class="valuelist" border="1" cellpadding="2" cellspacing="1" width="100%">
<tr><th width="25%">Constant</th><th width="15%">Value</th><th width="60%">Description</th></tr>
<tr><td valign="top"><tt>QAbstractSocket::IPv4Protocol</tt></td><td align="center" valign="top"><tt>0</tt></td><td valign="top">IPv4</td></tr>
<tr><td valign="top"><tt>QAbstractSocket::IPv6Protocol</tt></td><td align="center" valign="top"><tt>1</tt></td><td valign="top">IPv6</td></tr>
<tr><td valign="top"><tt>QAbstractSocket::UnknownNetworkLayerProtocol</tt></td><td align="center" valign="top"><tt>-1</tt></td><td valign="top">Other than IPv4 and IPv6</td></tr>
</table></p>
<p>See also <a href="qhostaddress.html#protocol">QHostAddress::protocol</a>().</p>
<a name="//apple_ref/cpp/tag/QAbstractSocket/SocketError"></a>
<a name="//apple_ref/cpp/econst/QAbstractSocket/ConnectionRefusedError"></a>
<a name="//apple_ref/cpp/econst/QAbstractSocket/RemoteHostClosedError"></a>
<a name="//apple_ref/cpp/econst/QAbstractSocket/HostNotFoundError"></a>
<a name="//apple_ref/cpp/econst/QAbstractSocket/SocketAccessError"></a>
<a name="//apple_ref/cpp/econst/QAbstractSocket/SocketResourceError"></a>
<a name="//apple_ref/cpp/econst/QAbstractSocket/SocketTimeoutError"></a>
<a name="//apple_ref/cpp/econst/QAbstractSocket/DatagramTooLargeError"></a>
<a name="//apple_ref/cpp/econst/QAbstractSocket/NetworkError"></a>
<a name="//apple_ref/cpp/econst/QAbstractSocket/AddressInUseError"></a>
<a name="//apple_ref/cpp/econst/QAbstractSocket/SocketAddressNotAvailableError"></a>
<a name="//apple_ref/cpp/econst/QAbstractSocket/UnsupportedSocketOperationError"></a>
<a name="//apple_ref/cpp/econst/QAbstractSocket/ProxyAuthenticationRequiredError"></a>
<a name="//apple_ref/cpp/econst/QAbstractSocket/SslHandshakeFailedError"></a>
<a name="//apple_ref/cpp/econst/QAbstractSocket/UnfinishedSocketOperationError"></a>
<a name="//apple_ref/cpp/econst/QAbstractSocket/ProxyConnectionRefusedError"></a>
<a name="//apple_ref/cpp/econst/QAbstractSocket/ProxyConnectionClosedError"></a>
<a name="//apple_ref/cpp/econst/QAbstractSocket/ProxyConnectionTimeoutError"></a>
<a name="//apple_ref/cpp/econst/QAbstractSocket/ProxyNotFoundError"></a>
<a name="//apple_ref/cpp/econst/QAbstractSocket/ProxyProtocolError"></a>
<a name="//apple_ref/cpp/econst/QAbstractSocket/UnknownSocketError"></a>
<h3 class="fn"><a name="SocketError-enum"></a>enum QAbstractSocket::SocketError</h3>
<p>This enum describes the socket errors that can occur.</p>
<p><table class="valuelist" border="1" cellpadding="2" cellspacing="1" width="100%">
<tr><th width="25%">Constant</th><th width="15%">Value</th><th width="60%">Description</th></tr>
<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>
<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. Note that the client socket (i.e&#x2e;, this socket) will be closed after the remote close notification has been sent.</td></tr>
<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>
<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>
<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&#x2e;, too many sockets).</td></tr>
<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>
<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>
<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&#x2e;, the network cable was accidentally plugged out).</td></tr>
<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>
<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>
<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&#x2e;, lack of IPv6 support).</td></tr>
<tr><td valign="top"><tt>QAbstractSocket::ProxyAuthenticationRequiredError</tt></td><td align="center" valign="top"><tt>12</tt></td><td valign="top">The socket is using a proxy, and the proxy requires authentication.</td></tr>
<tr><td valign="top"><tt>QAbstractSocket::SslHandshakeFailedError</tt></td><td align="center" valign="top"><tt>13</tt></td><td valign="top">The SSL/TLS handshake failed, so the connection was closed (only used in <a href="qsslsocket.html">QSslSocket</a>)</td></tr>
<tr><td valign="top"><tt>QAbstractSocket::UnfinishedSocketOperationError</tt></td><td align="center" valign="top"><tt>11</tt></td><td valign="top">Used by QAbstractSocketEngine only, The last operation attempted has not finished yet (still in progress in the background).</td></tr>
<tr><td valign="top"><tt>QAbstractSocket::ProxyConnectionRefusedError</tt></td><td align="center" valign="top"><tt>14</tt></td><td valign="top">Could not contact the proxy server because the connection to that server was denied</td></tr>
<tr><td valign="top"><tt>QAbstractSocket::ProxyConnectionClosedError</tt></td><td align="center" valign="top"><tt>15</tt></td><td valign="top">The connection to the proxy server was closed unexpectedly (before the connection to the final peer was established)</td></tr>
<tr><td valign="top"><tt>QAbstractSocket::ProxyConnectionTimeoutError</tt></td><td align="center" valign="top"><tt>16</tt></td><td valign="top">The connection to the proxy server timed out or the proxy server stopped responding in the authentication phase.</td></tr>
<tr><td valign="top"><tt>QAbstractSocket::ProxyNotFoundError</tt></td><td align="center" valign="top"><tt>17</tt></td><td valign="top">The proxy address set with <a href="qabstractsocket.html#setProxy">setProxy</a>() (or the application proxy) was not found.</td></tr>
<tr><td valign="top"><tt>QAbstractSocket::ProxyProtocolError</tt></td><td align="center" valign="top"><tt>18</tt></td><td valign="top">The connection negotiation with the proxy server because the response from the proxy server could not be understood.</td></tr>
<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>
</table></p>
<p>See also <a href="qabstractsocket.html#error">QAbstractSocket::error</a>().</p>
<a name="//apple_ref/cpp/tag/QAbstractSocket/SocketOption"></a>
<a name="//apple_ref/cpp/econst/QAbstractSocket/LowDelayOption"></a>
<a name="//apple_ref/cpp/econst/QAbstractSocket/KeepAliveOption"></a>
<h3 class="fn"><a name="SocketOption-enum"></a>enum QAbstractSocket::SocketOption</h3>
<p>This enum represents the options that can be set on a socket. If desired, they can be set after having received the <a href="qabstractsocket.html#connected">connected</a>() signal from the socket or after having received a new socket from a <a href="qtcpserver.html">QTcpServer</a>.</p>
<p><table class="valuelist" border="1" cellpadding="2" cellspacing="1" width="100%">
<tr><th width="25%">Constant</th><th width="15%">Value</th><th width="60%">Description</th></tr>
<tr><td valign="top"><tt>QAbstractSocket::LowDelayOption</tt></td><td align="center" valign="top"><tt>0</tt></td><td valign="top">Try to optimize the socket for low latency. For a <a href="qtcpsocket.html">QTcpSocket</a> this would set the TCP_NODELAY option and disable Nagle's algorithm. Set this to 1 to enable.</td></tr>
<tr><td valign="top"><tt>QAbstractSocket::KeepAliveOption</tt></td><td align="center" valign="top"><tt>1</tt></td><td valign="top">Set this to 1 to enable the SO_KEEPALIVE socket option</td></tr>
</table></p>
<p>This enum was introduced in Qt 4.6.</p>
<p>See also <a href="qabstractsocket.html#setSocketOption">QAbstractSocket::setSocketOption</a>() and <a href="qabstractsocket.html#socketOption">QAbstractSocket::socketOption</a>().</p>
<a name="//apple_ref/cpp/tag/QAbstractSocket/SocketState"></a>
<a name="//apple_ref/cpp/econst/QAbstractSocket/UnconnectedState"></a>
<a name="//apple_ref/cpp/econst/QAbstractSocket/HostLookupState"></a>
<a name="//apple_ref/cpp/econst/QAbstractSocket/ConnectingState"></a>
<a name="//apple_ref/cpp/econst/QAbstractSocket/ConnectedState"></a>
<a name="//apple_ref/cpp/econst/QAbstractSocket/BoundState"></a>
<a name="//apple_ref/cpp/econst/QAbstractSocket/ClosingState"></a>
<a name="//apple_ref/cpp/econst/QAbstractSocket/ListeningState"></a>
<a name="//apple_ref/cpp/econst/QAbstractSocket/Idle"></a>
<a name="//apple_ref/cpp/econst/QAbstractSocket/HostLookup"></a>
<a name="//apple_ref/cpp/econst/QAbstractSocket/Connecting"></a>
<a name="//apple_ref/cpp/econst/QAbstractSocket/Connected"></a>
<a name="//apple_ref/cpp/econst/QAbstractSocket/Closing"></a>
<a name="//apple_ref/cpp/econst/QAbstractSocket/Connection"></a>
<h3 class="fn"><a name="SocketState-enum"></a>enum QAbstractSocket::SocketState</h3>
<p>This enum describes the different states in which a socket can be.</p>
<p><table class="valuelist" border="1" cellpadding="2" cellspacing="1" width="100%">
<tr><th width="25%">Constant</th><th width="15%">Value</th><th width="60%">Description</th></tr>
<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>
<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>
<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>
<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>
<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>
<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>
<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>
</table></p>
<p>See also <a href="qabstractsocket.html#state">QAbstractSocket::state</a>().</p>
<a name="//apple_ref/cpp/tag/QAbstractSocket/SocketType"></a>
<a name="//apple_ref/cpp/econst/QAbstractSocket/TcpSocket"></a>
<a name="//apple_ref/cpp/econst/QAbstractSocket/UdpSocket"></a>
<a name="//apple_ref/cpp/econst/QAbstractSocket/UnknownSocketType"></a>
<h3 class="fn"><a name="SocketType-enum"></a>enum QAbstractSocket::SocketType</h3>
<p>This enum describes the transport layer protocol.</p>
<p><table class="valuelist" border="1" cellpadding="2" cellspacing="1" width="100%">
<tr><th width="25%">Constant</th><th width="15%">Value</th><th width="60%">Description</th></tr>
<tr><td valign="top"><tt>QAbstractSocket::TcpSocket</tt></td><td align="center" valign="top"><tt>0</tt></td><td valign="top">TCP</td></tr>
<tr><td valign="top"><tt>QAbstractSocket::UdpSocket</tt></td><td align="center" valign="top"><tt>1</tt></td><td valign="top">UDP</td></tr>
<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>
</table></p>
<p>See also <a href="qabstractsocket.html#socketType">QAbstractSocket::socketType</a>().</p>
<hr />
<h2>Member Function Documentation</h2>
<a name="//apple_ref/cpp/instm/QAbstractSocket/QAbstractSocket"></a>
<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>
<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>
<p>See also <a href="qabstractsocket.html#socketType">socketType</a>(), <a href="qtcpsocket.html">QTcpSocket</a>, and <a href="qudpsocket.html">QUdpSocket</a>.</p>
<a name="//apple_ref/cpp/instm/QAbstractSocket/~QAbstractSocket"></a>
<h3 class="fn"><a name="dtor.QAbstractSocket"></a>QAbstractSocket::~QAbstractSocket ()&nbsp;&nbsp;<tt> [virtual]</tt></h3>
<p>Destroys the socket.</p>
<a name="//apple_ref/cpp/instm/QAbstractSocket/abort"></a>
<h3 class="fn"><a name="abort"></a>void QAbstractSocket::abort ()</h3>
<p>Aborts the current connection and resets the socket. Unlike <a href="qabstractsocket.html#disconnectFromHost">disconnectFromHost</a>(), this function immediately closes the socket, discarding any pending data in the write buffer.</p>
<p>See also <a href="qabstractsocket.html#disconnectFromHost">disconnectFromHost</a>() and <a href="qabstractsocket.html#close">close</a>().</p>
<a name="//apple_ref/cpp/instm/QAbstractSocket/atEnd"></a>
<h3 class="fn"><a name="atEnd"></a>bool QAbstractSocket::atEnd () const&nbsp;&nbsp;<tt> [virtual]</tt></h3>
<p>Reimplemented from <a href="qiodevice.html#atEnd">QIODevice::atEnd</a>().</p>
<p>Returns true if no more data is currently available for reading; otherwise returns false.</p>
<p>This function is most commonly used when reading data from the socket in a loop. For example:</p>
<pre>  <span class="comment">// This slot is connected to QAbstractSocket::readyRead()</span>
  void SocketClass::readyReadSlot()
  {
      while (!socket.atEnd()) {
          QByteArray data = socket.read(100);
          ....
      }
  }</pre>
<p>See also <a href="qabstractsocket.html#bytesAvailable">bytesAvailable</a>() and <a href="qiodevice.html#readyRead">readyRead</a>().</p>
<a name="//apple_ref/cpp/instm/QAbstractSocket/bytesAvailable"></a>
<h3 class="fn"><a name="bytesAvailable"></a><a href="qtglobal.html#qint64-typedef">qint64</a> QAbstractSocket::bytesAvailable () const&nbsp;&nbsp;<tt> [virtual]</tt></h3>
<p>Reimplemented from <a href="qiodevice.html#bytesAvailable">QIODevice::bytesAvailable</a>().</p>
<p>Returns the number of incoming bytes that are waiting to be read.</p>
<p>See also <a href="qabstractsocket.html#bytesToWrite">bytesToWrite</a>() and <a href="qiodevice.html#read">read</a>().</p>
<a name="//apple_ref/cpp/instm/QAbstractSocket/bytesToWrite"></a>
<h3 class="fn"><a name="bytesToWrite"></a><a href="qtglobal.html#qint64-typedef">qint64</a> QAbstractSocket::bytesToWrite () const&nbsp;&nbsp;<tt> [virtual]</tt></h3>
<p>Reimplemented from <a href="qiodevice.html#bytesToWrite">QIODevice::bytesToWrite</a>().</p>
<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>
<p>See also <a href="qabstractsocket.html#bytesAvailable">bytesAvailable</a>() and <a href="qabstractsocket.html#flush">flush</a>().</p>
<a name="//apple_ref/cpp/instm/QAbstractSocket/canReadLine"></a>
<h3 class="fn"><a name="canReadLine"></a>bool QAbstractSocket::canReadLine () const&nbsp;&nbsp;<tt> [virtual]</tt></h3>
<p>Reimplemented from <a href="qiodevice.html#canReadLine">QIODevice::canReadLine</a>().</p>
<p>Returns true if a line of data can be read from the socket; otherwise returns false.</p>
<p>See also <a href="qiodevice.html#readLine">readLine</a>().</p>
<a name="//apple_ref/cpp/instm/QAbstractSocket/close"></a>
<h3 class="fn"><a name="close"></a>void QAbstractSocket::close ()&nbsp;&nbsp;<tt> [virtual]</tt></h3>
<p>Reimplemented from <a href="qiodevice.html#close">QIODevice::close</a>().</p>
<p>Closes the I/O device for the socket, disconnects the socket's connection with the host, closes the socket, and resets the name, address, port number and underlying socket descriptor.</p>
<p>See <a href="qiodevice.html#close">QIODevice::close</a>() for a description of the actions that occur when an I/O device is closed.</p>
<p>See also <a href="qabstractsocket.html#abort">abort</a>().</p>
<a name="//apple_ref/cpp/instm/QAbstractSocket/connectToHost"></a>
<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>
<p>Attempts to make a connection to <i>hostName</i> on the given <i>port</i>.</p>
<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>
<p>At any point, the socket can emit <a href="qabstractsocket.html#error">error</a>() to signal that an error occurred.</p>
<p><i>hostName</i> may be an IP address in string form (e.g&#x2e;, &quot;43.195.83.32&quot;), or it may be a host name (e.g&#x2e;, &quot;example.com&quot;). <a href="qabstractsocket.html">QAbstractSocket</a> will do a lookup only if required. <i>port</i> is in native byte order.</p>
<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>
<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>
<p>This is an overloaded function.</p>
<p>Attempts to make a connection to <i>address</i> on port <i>port</i>.</p>
<a name="//apple_ref/cpp/instm/QAbstractSocket/connectToHostImplementation"></a>
<h3 class="fn"><a name="connectToHostImplementation"></a>void QAbstractSocket::connectToHostImplementation ( 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 )&nbsp;&nbsp;<tt> [protected slot]</tt></h3>
<p>Contains the implementation of <a href="qabstractsocket.html#connectToHost">connectToHost</a>().</p>
<p>Attempts to make a connection to <i>hostName</i> on the given <i>port</i>. The socket is opened in the given <i>openMode</i>.</p>
<p>This function was introduced in Qt 4.1.</p>
<a name="//apple_ref/cpp/instm/QAbstractSocket/connected"></a>
<h3 class="fn"><a name="connected"></a>void QAbstractSocket::connected ()&nbsp;&nbsp;<tt> [signal]</tt></h3>
<p>This signal is emitted after <a href="qabstractsocket.html#connectToHost">connectToHost</a>() has been called and a connection has been successfully established.</p>
<p><b>Note:</b> On some operating systems the connected() signal may be directly emitted from the <a href="qabstractsocket.html#connectToHost">connectToHost</a>() call for connections to the localhost.</p>
<p>See also <a href="qabstractsocket.html#connectToHost">connectToHost</a>() and <a href="qabstractsocket.html#disconnected">disconnected</a>().</p>
<a name="//apple_ref/cpp/instm/QAbstractSocket/disconnectFromHost"></a>
<h3 class="fn"><a name="disconnectFromHost"></a>void QAbstractSocket::disconnectFromHost ()</h3>
<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>
<p>See also <a href="qabstractsocket.html#connectToHost">connectToHost</a>().</p>
<a name="//apple_ref/cpp/instm/QAbstractSocket/disconnectFromHostImplementation"></a>
<h3 class="fn"><a name="disconnectFromHostImplementation"></a>void QAbstractSocket::disconnectFromHostImplementation ()&nbsp;&nbsp;<tt> [protected slot]</tt></h3>
<p>Contains the implementation of <a href="qabstractsocket.html#disconnectFromHost">disconnectFromHost</a>().</p>
<p>This function was introduced in Qt 4.1.</p>
<a name="//apple_ref/cpp/instm/QAbstractSocket/disconnected"></a>
<h3 class="fn"><a name="disconnected"></a>void QAbstractSocket::disconnected ()&nbsp;&nbsp;<tt> [signal]</tt></h3>
<p>This signal is emitted when the socket has been disconnected.</p>
<p><b>Warning:</b> If you need to delete the <a href="qobject.html#sender">sender</a>() of this signal in a slot connected to it, use the <a href="qobject.html#deleteLater">deleteLater()</a> function.</p>
<p>See also <a href="qabstractsocket.html#connectToHost">connectToHost</a>(), <a href="qabstractsocket.html#disconnectFromHost">disconnectFromHost</a>(), and <a href="qabstractsocket.html#abort">abort</a>().</p>
<a name="//apple_ref/cpp/instm/QAbstractSocket/error"></a>
<h3 class="fn"><a name="error"></a><a href="qabstractsocket.html#SocketError-enum">SocketError</a> QAbstractSocket::error () const</h3>
<p>Returns the type of error that last occurred.</p>
<p>See also <a href="qabstractsocket.html#state">state</a>() and <a href="qiodevice.html#errorString">errorString</a>().</p>
<h3 class="fn"><a name="error-2"></a>void QAbstractSocket::error ( <a href="qabstractsocket.html#SocketError-enum">QAbstractSocket::SocketError</a> <i>socketError</i> )&nbsp;&nbsp;<tt> [signal]</tt></h3>
<p>This signal is emitted after an error occurred. The <i>socketError</i> parameter describes the type of error that occurred.</p>
<p><a href="qabstractsocket.html#SocketError-enum">QAbstractSocket::SocketError</a> is not a registered metatype, so for queued connections, you will have to register it with <a href="qmetatype.html#Q_DECLARE_METATYPE">Q_DECLARE_METATYPE</a>() and <a href="qmetatype.html#qRegisterMetaType">qRegisterMetaType</a>().</p>
<p>See also <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>
<a name="//apple_ref/cpp/instm/QAbstractSocket/flush"></a>
<h3 class="fn"><a name="flush"></a>bool QAbstractSocket::flush ()</h3>
<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>
<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>
<p>See also <a href="qiodevice.html#write">write</a>() and <a href="qabstractsocket.html#waitForBytesWritten">waitForBytesWritten</a>().</p>
<a name="//apple_ref/cpp/instm/QAbstractSocket/hostFound"></a>
<h3 class="fn"><a name="hostFound"></a>void QAbstractSocket::hostFound ()&nbsp;&nbsp;<tt> [signal]</tt></h3>
<p>This signal is emitted after <a href="qabstractsocket.html#connectToHost">connectToHost</a>() has been called and the host lookup has succeeded.</p>
<p><b>Note:</b> Since Qt 4.6&#x2e;3 <a href="qabstractsocket.html">QAbstractSocket</a> may emit hostFound() directly from the <a href="qabstractsocket.html#connectToHost">connectToHost</a>() call since a DNS result could have been cached.</p>
<p>See also <a href="qabstractsocket.html#connected">connected</a>().</p>
<a name="//apple_ref/cpp/instm/QAbstractSocket/isSequential"></a>
<h3 class="fn"><a name="isSequential"></a>bool QAbstractSocket::isSequential () const&nbsp;&nbsp;<tt> [virtual]</tt></h3>
<p>Reimplemented from <a href="qiodevice.html#isSequential">QIODevice::isSequential</a>().</p>
<a name="//apple_ref/cpp/instm/QAbstractSocket/isValid"></a>
<h3 class="fn"><a name="isValid"></a>bool QAbstractSocket::isValid () const</h3>
<p>Returns true if the socket is valid and ready for use; otherwise returns false.</p>
<p><b>Note:</b> The socket's state must be <a href="qabstractsocket.html#SocketState-enum">ConnectedState</a> before reading and writing can occur.</p>
<p>See also <a href="qabstractsocket.html#state">state</a>().</p>
<a name="//apple_ref/cpp/instm/QAbstractSocket/localAddress"></a>
<h3 class="fn"><a name="localAddress"></a><a href="qhostaddress.html">QHostAddress</a> QAbstractSocket::localAddress () const</h3>
<p>Returns the host address of the local socket if available; otherwise returns <a href="qhostaddress.html#SpecialAddress-enum">QHostAddress::Null</a>.</p>
<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&#x2e;0&#x2e;1) for connections to the local host.</p>
<p>See also <a href="qabstractsocket.html#localPort">localPort</a>(), <a href="qabstractsocket.html#peerAddress">peerAddress</a>(), and <a href="qabstractsocket.html#setLocalAddress">setLocalAddress</a>().</p>
<a name="//apple_ref/cpp/instm/QAbstractSocket/localPort"></a>
<h3 class="fn"><a name="localPort"></a><a href="qtglobal.html#quint16-typedef">quint16</a> QAbstractSocket::localPort () const</h3>
<p>Returns the host port number (in native byte order) of the local socket if available; otherwise returns 0.</p>
<p>See also <a href="qabstractsocket.html#localAddress">localAddress</a>(), <a href="qabstractsocket.html#peerPort">peerPort</a>(), and <a href="qabstractsocket.html#setLocalPort">setLocalPort</a>().</p>
<a name="//apple_ref/cpp/instm/QAbstractSocket/peerAddress"></a>
<h3 class="fn"><a name="peerAddress"></a><a href="qhostaddress.html">QHostAddress</a> QAbstractSocket::peerAddress () const</h3>
<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>
<p>See also <a href="qabstractsocket.html#peerName">peerName</a>(), <a href="qabstractsocket.html#peerPort">peerPort</a>(), <a href="qabstractsocket.html#localAddress">localAddress</a>(), and <a href="qabstractsocket.html#setPeerAddress">setPeerAddress</a>().</p>
<a name="//apple_ref/cpp/instm/QAbstractSocket/peerName"></a>
<h3 class="fn"><a name="peerName"></a><a href="qstring.html">QString</a> QAbstractSocket::peerName () const</h3>
<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>
<p>See also <a href="qabstractsocket.html#peerAddress">peerAddress</a>(), <a href="qabstractsocket.html#peerPort">peerPort</a>(), and <a href="qabstractsocket.html#setPeerName">setPeerName</a>().</p>
<a name="//apple_ref/cpp/instm/QAbstractSocket/peerPort"></a>
<h3 class="fn"><a name="peerPort"></a><a href="qtglobal.html#quint16-typedef">quint16</a> QAbstractSocket::peerPort () const</h3>
<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>
<p>See also <a href="qabstractsocket.html#peerAddress">peerAddress</a>(), <a href="qabstractsocket.html#localPort">localPort</a>(), and <a href="qabstractsocket.html#setPeerPort">setPeerPort</a>().</p>
<a name="//apple_ref/cpp/instm/QAbstractSocket/proxy"></a>
<h3 class="fn"><a name="proxy"></a><a href="qnetworkproxy.html">QNetworkProxy</a> QAbstractSocket::proxy () const</h3>
<p>Returns the network proxy for this socket. By default <a href="qnetworkproxy.html#ProxyType-enum">QNetworkProxy::DefaultProxy</a> is used, which means this socket will query the default proxy settings for the application.</p>
<p>This function was introduced in Qt 4.1.</p>
<p>See also <a href="qabstractsocket.html#setProxy">setProxy</a>(), <a href="qnetworkproxy.html">QNetworkProxy</a>, and <a href="qnetworkproxyfactory.html">QNetworkProxyFactory</a>.</p>
<a name="//apple_ref/cpp/instm/QAbstractSocket/proxyAuthenticationRequired"></a>
<h3 class="fn"><a name="proxyAuthenticationRequired"></a>void QAbstractSocket::proxyAuthenticationRequired ( const <a href="qnetworkproxy.html">QNetworkProxy</a> &amp; <i>proxy</i>, <a href="qauthenticator.html">QAuthenticator</a> * <i>authenticator</i> )&nbsp;&nbsp;<tt> [signal]</tt></h3>
<p>This signal can be emitted when a <i>proxy</i> that requires authentication is used. The <i>authenticator</i> object can then be filled in with the required details to allow authentication and continue the connection.</p>
<p><b>Note:</b> It is not possible to use a QueuedConnection to connect to this signal, as the connection will fail if the authenticator has not been filled in with new information when the signal returns.</p>
<p>This function was introduced in Qt 4.3.</p>
<p>See also <a href="qauthenticator.html">QAuthenticator</a> and <a href="qnetworkproxy.html">QNetworkProxy</a>.</p>
<a name="//apple_ref/cpp/instm/QAbstractSocket/readBufferSize"></a>
<h3 class="fn"><a name="readBufferSize"></a><a href="qtglobal.html#qint64-typedef">qint64</a> QAbstractSocket::readBufferSize () const</h3>
<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>
<p>A read buffer size of 0 (the default) means that the buffer has no size limit, ensuring that no data is lost.</p>
<p>See also <a href="qabstractsocket.html#setReadBufferSize">setReadBufferSize</a>() and <a href="qiodevice.html#read">read</a>().</p>
<a name="//apple_ref/cpp/instm/QAbstractSocket/readData"></a>
<h3 class="fn"><a name="readData"></a><a href="qtglobal.html#qint64-typedef">qint64</a> QAbstractSocket::readData ( char * <i>data</i>, <a href="qtglobal.html#qint64-typedef">qint64</a> <i>maxSize</i> )&nbsp;&nbsp;<tt> [virtual protected]</tt></h3>
<p>Reimplemented from <a href="qiodevice.html#readData">QIODevice::readData</a>().</p>
<a name="//apple_ref/cpp/instm/QAbstractSocket/readLineData"></a>
<h3 class="fn"><a name="readLineData"></a><a href="qtglobal.html#qint64-typedef">qint64</a> QAbstractSocket::readLineData ( char * <i>data</i>, <a href="qtglobal.html#qint64-typedef">qint64</a> <i>maxlen</i> )&nbsp;&nbsp;<tt> [virtual protected]</tt></h3>
<p>Reimplemented from <a href="qiodevice.html#readLineData">QIODevice::readLineData</a>().</p>
<a name="//apple_ref/cpp/instm/QAbstractSocket/setLocalAddress"></a>
<h3 class="fn"><a name="setLocalAddress"></a>void QAbstractSocket::setLocalAddress ( const <a href="qhostaddress.html">QHostAddress</a> &amp; <i>address</i> )&nbsp;&nbsp;<tt> [protected]</tt></h3>
<p>Sets the address on the local side of a connection to <i>address</i>.</p>
<p>You can call this function in a subclass of <a href="qabstractsocket.html">QAbstractSocket</a> to change the return value of the <a href="qabstractsocket.html#localAddress">localAddress</a>() function after a connection has been established. This feature is commonly used by proxy connections for virtual connection settings.</p>
<p>Note that this function does not bind the local address of the socket prior to a connection (e.g&#x2e;, <a href="qudpsocket.html#bind">QUdpSocket::bind</a>()).</p>
<p>This function was introduced in Qt 4.1.</p>
<p>See also <a href="qabstractsocket.html#localAddress">localAddress</a>(), <a href="qabstractsocket.html#setLocalPort">setLocalPort</a>(), and <a href="qabstractsocket.html#setPeerAddress">setPeerAddress</a>().</p>
<a name="//apple_ref/cpp/instm/QAbstractSocket/setLocalPort"></a>
<h3 class="fn"><a name="setLocalPort"></a>void QAbstractSocket::setLocalPort ( <a href="qtglobal.html#quint16-typedef">quint16</a> <i>port</i> )&nbsp;&nbsp;<tt> [protected]</tt></h3>
<p>Sets the port on the local side of a connection to <i>port</i>.</p>
<p>You can call this function in a subclass of <a href="qabstractsocket.html">QAbstractSocket</a> to change the return value of the <a href="qabstractsocket.html#localPort">localPort</a>() function after a connection has been established. This feature is commonly used by proxy connections for virtual connection settings.</p>
<p>Note that this function does not bind the local port of the socket prior to a connection (e.g&#x2e;, <a href="qudpsocket.html#bind">QUdpSocket::bind</a>()).</p>
<p>This function was introduced in Qt 4.1.</p>
<p>See also <a href="qabstractsocket.html#localPort">localPort</a>(), <a href="qabstractsocket.html#localAddress">localAddress</a>(), <a href="qabstractsocket.html#setLocalAddress">setLocalAddress</a>(), and <a href="qabstractsocket.html#setPeerPort">setPeerPort</a>().</p>
<a name="//apple_ref/cpp/instm/QAbstractSocket/setPeerAddress"></a>
<h3 class="fn"><a name="setPeerAddress"></a>void QAbstractSocket::setPeerAddress ( const <a href="qhostaddress.html">QHostAddress</a> &amp; <i>address</i> )&nbsp;&nbsp;<tt> [protected]</tt></h3>
<p>Sets the address of the remote side of the connection to <i>address</i>.</p>
<p>You can call this function in a subclass of <a href="qabstractsocket.html">QAbstractSocket</a> to change the return value of the <a href="qabstractsocket.html#peerAddress">peerAddress</a>() function after a connection has been established. This feature is commonly used by proxy connections for virtual connection settings.</p>
<p>This function was introduced in Qt 4.1.</p>
<p>See also <a href="qabstractsocket.html#peerAddress">peerAddress</a>(), <a href="qabstractsocket.html#setPeerPort">setPeerPort</a>(), and <a href="qabstractsocket.html#setLocalAddress">setLocalAddress</a>().</p>
<a name="//apple_ref/cpp/instm/QAbstractSocket/setPeerName"></a>
<h3 class="fn"><a name="setPeerName"></a>void QAbstractSocket::setPeerName ( const <a href="qstring.html">QString</a> &amp; <i>name</i> )&nbsp;&nbsp;<tt> [protected]</tt></h3>
<p>Sets the host name of the remote peer to <i>name</i>.</p>
<p>You can call this function in a subclass of <a href="qabstractsocket.html">QAbstractSocket</a> to change the return value of the <a href="qabstractsocket.html#peerName">peerName</a>() function after a connection has been established. This feature is commonly used by proxy connections for virtual connection settings.</p>
<p>This function was introduced in Qt 4.1.</p>
<p>See also <a href="qabstractsocket.html#peerName">peerName</a>().</p>
<a name="//apple_ref/cpp/instm/QAbstractSocket/setPeerPort"></a>
<h3 class="fn"><a name="setPeerPort"></a>void QAbstractSocket::setPeerPort ( <a href="qtglobal.html#quint16-typedef">quint16</a> <i>port</i> )&nbsp;&nbsp;<tt> [protected]</tt></h3>
<p>Sets the port of the remote side of the connection to <i>port</i>.</p>
<p>You can call this function in a subclass of <a href="qabstractsocket.html">QAbstractSocket</a> to change the return value of the <a href="qabstractsocket.html#peerPort">peerPort</a>() function after a connection has been established. This feature is commonly used by proxy connections for virtual connection settings.</p>
<p>This function was introduced in Qt 4.1.</p>
<p>See also <a href="qabstractsocket.html#peerPort">peerPort</a>(), <a href="qabstractsocket.html#setPeerAddress">setPeerAddress</a>(), and <a href="qabstractsocket.html#setLocalPort">setLocalPort</a>().</p>
<a name="//apple_ref/cpp/instm/QAbstractSocket/setProxy"></a>
<h3 class="fn"><a name="setProxy"></a>void QAbstractSocket::setProxy ( const <a href="qnetworkproxy.html">QNetworkProxy</a> &amp; <i>networkProxy</i> )</h3>
<p>Sets the explicit network proxy for this socket to <i>networkProxy</i>.</p>
<p>To disable the use of a proxy for this socket, use the <a href="qnetworkproxy.html#ProxyType-enum">QNetworkProxy::NoProxy</a> proxy type:</p>
<pre> socket-&gt;setProxy(QNetworkProxy::NoProxy);</pre>
<p>The default value for the proxy is <a href="qnetworkproxy.html#ProxyType-enum">QNetworkProxy::DefaultProxy</a>, which means the socket will use the application settings: if a proxy is set with QNetworkProxy::setApplicationProxy, it will use that; otherwise, if a factory is set with QNetworkProxyFactory::setApplicationProxyFactory, it will query that factory with type <a href="qnetworkproxyquery.html#QueryType-enum">QNetworkProxyQuery::TcpSocket</a>.</p>
<p>This function was introduced in Qt 4.1.</p>
<p>See also <a href="qabstractsocket.html#proxy">proxy</a>(), <a href="qnetworkproxy.html">QNetworkProxy</a>, and <a href="qnetworkproxyfactory.html#queryProxy">QNetworkProxyFactory::queryProxy</a>().</p>
<a name="//apple_ref/cpp/instm/QAbstractSocket/setReadBufferSize"></a>
<h3 class="fn"><a name="setReadBufferSize"></a>void QAbstractSocket::setReadBufferSize ( <a href="qtglobal.html#qint64-typedef">qint64</a> <i>size</i> )</h3>
<p>Sets the size of <a href="qabstractsocket.html">QAbstractSocket</a>'s internal read buffer to be <i>size</i> bytes.</p>
<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>
<p>This option is useful if you only read the data at certain points in time (e.g&#x2e;, 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>
<p>Only <a href="qtcpsocket.html">QTcpSocket</a> uses <a href="qabstractsocket.html">QAbstractSocket</a>'s internal buffer; <a href="qudpsocket.html">QUdpSocket</a> does not use any buffering at all, but rather relies on the implicit buffering provided by the operating system. Because of this, calling this function on <a href="qudpsocket.html">QUdpSocket</a> has no effect.</p>
<p>See also <a href="qabstractsocket.html#readBufferSize">readBufferSize</a>() and <a href="qiodevice.html#read">read</a>().</p>
<a name="//apple_ref/cpp/instm/QAbstractSocket/setSocketDescriptor"></a>
<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>
<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>
<p><b>Note:</b> It is not possible to initialize two abstract sockets with the same native socket descriptor.</p>
<p>See also <a href="qabstractsocket.html#socketDescriptor">socketDescriptor</a>().</p>
<a name="//apple_ref/cpp/instm/QAbstractSocket/setSocketError"></a>
<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>
<p>Sets the type of error that last occurred to <i>socketError</i>.</p>
<p>See also <a href="qabstractsocket.html#setSocketState">setSocketState</a>() and <a href="qiodevice.html#setErrorString">setErrorString</a>().</p>
<a name="//apple_ref/cpp/instm/QAbstractSocket/setSocketOption"></a>
<h3 class="fn"><a name="setSocketOption"></a>void QAbstractSocket::setSocketOption ( <a href="qabstractsocket.html#SocketOption-enum">QAbstractSocket::SocketOption</a> <i>option</i>, const <a href="qvariant.html">QVariant</a> &amp; <i>value</i> )</h3>
<p>Sets the given <i>option</i> to the value described by <i>value</i>.</p>
<p>This function was introduced in Qt 4.6.</p>
<p>See also <a href="qabstractsocket.html#socketOption">socketOption</a>().</p>
<a name="//apple_ref/cpp/instm/QAbstractSocket/setSocketState"></a>
<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>
<p>Sets the state of the socket to <i>state</i>.</p>
<p>See also <a href="qabstractsocket.html#state">state</a>().</p>
<a name="//apple_ref/cpp/instm/QAbstractSocket/socketDescriptor"></a>
<h3 class="fn"><a name="socketDescriptor"></a>int QAbstractSocket::socketDescriptor () const</h3>
<p>Returns the native socket descriptor of the <a href="qabstractsocket.html">QAbstractSocket</a> object if this is available; otherwise returns -1.</p>
<p>If the socket is using <a href="qnetworkproxy.html">QNetworkProxy</a>, the returned descriptor may not be usable with native socket functions.</p>
<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>
<p>See also <a href="qabstractsocket.html#setSocketDescriptor">setSocketDescriptor</a>().</p>
<a name="//apple_ref/cpp/instm/QAbstractSocket/socketOption"></a>
<h3 class="fn"><a name="socketOption"></a><a href="qvariant.html">QVariant</a> QAbstractSocket::socketOption ( <a href="qabstractsocket.html#SocketOption-enum">QAbstractSocket::SocketOption</a> <i>option</i> )</h3>
<p>Returns the value of the <i>option</i> option.</p>
<p>This function was introduced in Qt 4.6.</p>
<p>See also <a href="qabstractsocket.html#setSocketOption">setSocketOption</a>().</p>
<a name="//apple_ref/cpp/instm/QAbstractSocket/socketType"></a>
<h3 class="fn"><a name="socketType"></a><a href="qabstractsocket.html#SocketType-enum">SocketType</a> QAbstractSocket::socketType () const</h3>
<p>Returns the socket type (TCP, UDP, or other).</p>
<p>See also <a href="qtcpsocket.html">QTcpSocket</a> and <a href="qudpsocket.html">QUdpSocket</a>.</p>
<a name="//apple_ref/cpp/instm/QAbstractSocket/state"></a>
<h3 class="fn"><a name="state"></a><a href="qabstractsocket.html#SocketState-enum">SocketState</a> QAbstractSocket::state () const</h3>
<p>Returns the state of the socket.</p>
<p>See also <a href="qabstractsocket.html#error">error</a>().</p>
<a name="//apple_ref/cpp/instm/QAbstractSocket/stateChanged"></a>
<h3 class="fn"><a name="stateChanged"></a>void QAbstractSocket::stateChanged ( <a href="qabstractsocket.html#SocketState-enum">QAbstractSocket::SocketState</a> <i>socketState</i> )&nbsp;&nbsp;<tt> [signal]</tt></h3>
<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>
<p><a href="qabstractsocket.html#SocketState-enum">QAbstractSocket::SocketState</a> is not a registered metatype, so for queued connections, you will have to register it with Q_REGISTER_METATYPE() and <a href="qmetatype.html#qRegisterMetaType">qRegisterMetaType</a>().</p>
<p>See also <a href="qabstractsocket.html#state">state</a>() and <a href="custom-types.html">Creating Custom Qt Types</a>.</p>
<a name="//apple_ref/cpp/instm/QAbstractSocket/waitForBytesWritten"></a>
<h3 class="fn"><a name="waitForBytesWritten"></a>bool QAbstractSocket::waitForBytesWritten ( int <i>msecs</i> = 30000 )&nbsp;&nbsp;<tt> [virtual]</tt></h3>
<p>Reimplemented from <a href="qiodevice.html#waitForBytesWritten">QIODevice::waitForBytesWritten</a>().</p>
<a name="//apple_ref/cpp/instm/QAbstractSocket/waitForConnected"></a>
<h3 class="fn"><a name="waitForConnected"></a>bool QAbstractSocket::waitForConnected ( int <i>msecs</i> = 30000 )</h3>
<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>
<p>The following example waits up to one second for a connection to be established:</p>
<pre> socket-&gt;connectToHost(&quot;imap&quot;, 143);
 if (socket-&gt;waitForConnected(1000))
     qDebug(&quot;Connected!&quot;);</pre>
<p>If msecs is -1, this function will not time out.</p>
<p><b>Note:</b> This function may wait slightly longer than <i>msecs</i>, depending on the time it takes to complete the host lookup.</p>
<p><b>Note:</b> Multiple calls to this functions do not accumulate the time. If the function times out, the connecting process will be aborted.</p>
<p>See also <a href="qabstractsocket.html#connectToHost">connectToHost</a>() and <a href="qabstractsocket.html#connected">connected</a>().</p>
<a name="//apple_ref/cpp/instm/QAbstractSocket/waitForDisconnected"></a>
<h3 class="fn"><a name="waitForDisconnected"></a>bool QAbstractSocket::waitForDisconnected ( int <i>msecs</i> = 30000 )</h3>
<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>
<p>The following example waits up to one second for a connection to be closed:</p>
<pre> socket-&gt;disconnectFromHost();
     if (socket-&gt;state() == QAbstractSocket::UnconnectedState ||
         socket-&gt;waitForDisconnected(1000))
         qDebug(&quot;Disconnected!&quot;);</pre>
<p>If msecs is -1, this function will not time out.</p>
<p>See also <a href="qabstractsocket.html#disconnectFromHost">disconnectFromHost</a>() and <a href="qabstractsocket.html#close">close</a>().</p>
<a name="//apple_ref/cpp/instm/QAbstractSocket/waitForReadyRead"></a>
<h3 class="fn"><a name="waitForReadyRead"></a>bool QAbstractSocket::waitForReadyRead ( int <i>msecs</i> = 30000 )&nbsp;&nbsp;<tt> [virtual]</tt></h3>
<p>Reimplemented from <a href="qiodevice.html#waitForReadyRead">QIODevice::waitForReadyRead</a>().</p>
<p>This function blocks until new data is available for reading and the <a href="qiodevice.html#readyRead">readyRead()</a> signal has been emitted. The function will timeout after <i>msecs</i> milliseconds; the default timeout is 30000 milliseconds.</p>
<p>The function returns true if the <a href="qiodevice.html#readyRead">readyRead</a>() signal is emitted and there is new data available for reading; otherwise it returns false (if an error occurred or the operation timed out).</p>
<p>See also <a href="qabstractsocket.html#waitForBytesWritten">waitForBytesWritten</a>().</p>
<a name="//apple_ref/cpp/instm/QAbstractSocket/writeData"></a>
<h3 class="fn"><a name="writeData"></a><a href="qtglobal.html#qint64-typedef">qint64</a> QAbstractSocket::writeData ( const char * <i>data</i>, <a href="qtglobal.html#qint64-typedef">qint64</a> <i>size</i> )&nbsp;&nbsp;<tt> [virtual protected]</tt></h3>
<p>Reimplemented from <a href="qiodevice.html#writeData">QIODevice::writeData</a>().</p>
<p /><address><hr /><div align="center">
<table width="100%" cellspacing="0" border="0"><tr class="address">
<td width="40%" align="left">Copyright &copy; 2010 Nokia Corporation and/or its subsidiary(-ies)</td>
<td width="20%" align="center"><a href="trademarks.html">Trademarks</a></td>
<td width="40%" align="right"><div align="right">Qt 4.6.3</div></td>
</tr></table></div></address></body>
</html>