<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html> <html lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <!-- qtcpserver.cpp --> <title>QTcpServer Class | Qt Network 5.12.2</title> <link rel="stylesheet" type="text/css" href="style/offline-simple.css" /> <script type="text/javascript"> document.getElementsByTagName("link").item(0).setAttribute("href", "style/offline.css"); // loading style sheet breaks anchors that were jumped to before // so force jumping to anchor again setTimeout(function() { var anchor = location.hash; // need to jump to different anchor first (e.g. none) location.hash = "#"; setTimeout(function() { location.hash = anchor; }, 0); }, 0); </script> </head> <body> <div class="header" id="qtdocheader"> <div class="main"> <div class="main-rounded"> <div class="navigationbar"> <table><tr> <td >Qt 5.12</td><td ><a href="qtnetwork-index.html">Qt Network</a></td><td ><a href="qtnetwork-module.html">C++ Classes</a></td><td >QTcpServer</td></tr></table><table class="buildversion"><tr> <td id="buildversion" width="100%" align="right"><a href="qtnetwork-index.html">Qt 5.12.2 Reference Documentation</a></td> </tr></table> </div> </div> <div class="content"> <div class="line"> <div class="content mainContent"> <div class="sidebar"> <div class="toc"> <h3><a name="toc">Contents</a></h3> <ul> <li class="level1"><a href="#public-functions">Public Functions</a></li> <li class="level1"><a href="#signals">Signals</a></li> <li class="level1"><a href="#static-public-members">Static Public Members</a></li> <li class="level1"><a href="#protected-functions">Protected Functions</a></li> <li class="level1"><a href="#details">Detailed Description</a></li> </ul> </div> <div class="sidebar-content" id="sidebar-content"></div></div> <h1 class="title">QTcpServer Class</h1> <!-- $$$QTcpServer-brief --> <p>The <a href="qtcpserver.html">QTcpServer</a> class provides a TCP-based server. <a href="#details">More...</a></p> <!-- @@@QTcpServer --> <div class="table"><table class="alignedsummary"> <tr><td class="memItemLeft rightAlign topAlign"> Header:</td><td class="memItemRight bottomAlign"> <span class="preprocessor">#include <QTcpServer></span> </td></tr><tr><td class="memItemLeft rightAlign topAlign"> qmake:</td><td class="memItemRight bottomAlign"> QT += network</td></tr><tr><td class="memItemLeft rightAlign topAlign"> Inherits:</td><td class="memItemRight bottomAlign"> <a href="../qtcore/qobject.html">QObject</a></td></tr><tr><td class="memItemLeft rightAlign topAlign"> Inherited By:</td><td class="memItemRight bottomAlign"> <p><a href="qsctpserver.html">QSctpServer</a></p> </td></tr></table></div><ul> <li><a href="qtcpserver-members.html">List of all members, including inherited members</a></li> <li><a href="qtcpserver-obsolete.html">Obsolete members</a></li> </ul> <p><b>Note:</b> All functions in this class are reentrant.</p> <a name="public-functions"></a> <h2 id="public-functions">Public Functions</h2> <div class="table"><table class="alignedsummary"> <tr><td class="memItemLeft rightAlign topAlign"> </td><td class="memItemRight bottomAlign"><b><a href="qtcpserver.html#QTcpServer">QTcpServer</a></b>(QObject *<i>parent</i> = nullptr)</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> virtual </td><td class="memItemRight bottomAlign"><b><a href="qtcpserver.html#dtor.QTcpServer">~QTcpServer</a></b>()</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qtcpserver.html#close">close</a></b>()</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> QString </td><td class="memItemRight bottomAlign"><b><a href="qtcpserver.html#errorString">errorString</a></b>() const</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> virtual bool </td><td class="memItemRight bottomAlign"><b><a href="qtcpserver.html#hasPendingConnections">hasPendingConnections</a></b>() const</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qtcpserver.html#isListening">isListening</a></b>() const</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qtcpserver.html#listen">listen</a></b>(const QHostAddress &<i>address</i> = QHostAddress::Any, quint16 <i>port</i> = 0)</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> int </td><td class="memItemRight bottomAlign"><b><a href="qtcpserver.html#maxPendingConnections">maxPendingConnections</a></b>() const</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> virtual QTcpSocket *</td><td class="memItemRight bottomAlign"><b><a href="qtcpserver.html#nextPendingConnection">nextPendingConnection</a></b>()</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qtcpserver.html#pauseAccepting">pauseAccepting</a></b>()</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> QNetworkProxy </td><td class="memItemRight bottomAlign"><b><a href="qtcpserver.html#proxy">proxy</a></b>() const</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qtcpserver.html#resumeAccepting">resumeAccepting</a></b>()</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> QHostAddress </td><td class="memItemRight bottomAlign"><b><a href="qtcpserver.html#serverAddress">serverAddress</a></b>() const</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> QAbstractSocket::SocketError </td><td class="memItemRight bottomAlign"><b><a href="qtcpserver.html#serverError">serverError</a></b>() const</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> quint16 </td><td class="memItemRight bottomAlign"><b><a href="qtcpserver.html#serverPort">serverPort</a></b>() const</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qtcpserver.html#setMaxPendingConnections">setMaxPendingConnections</a></b>(int <i>numConnections</i>)</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qtcpserver.html#setProxy">setProxy</a></b>(const QNetworkProxy &<i>networkProxy</i>)</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qtcpserver.html#setSocketDescriptor">setSocketDescriptor</a></b>(qintptr <i>socketDescriptor</i>)</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> qintptr </td><td class="memItemRight bottomAlign"><b><a href="qtcpserver.html#socketDescriptor">socketDescriptor</a></b>() const</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qtcpserver.html#waitForNewConnection">waitForNewConnection</a></b>(int <i>msec</i> = 0, bool *<i>timedOut</i> = nullptr)</td></tr> </table></div> <ul> <li class="fn">31 public functions inherited from <a href="../qtcore/qobject.html#public-functions">QObject</a></li> </ul> <a name="signals"></a> <h2 id="signals">Signals</h2> <div class="table"><table class="alignedsummary"> <tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qtcpserver.html#acceptError">acceptError</a></b>(QAbstractSocket::SocketError <i>socketError</i>)</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qtcpserver.html#newConnection">newConnection</a></b>()</td></tr> </table></div> <ul> <li class="fn">2 signals inherited from <a href="../qtcore/qobject.html#signals">QObject</a></li> </ul> <a name="static-public-members"></a> <h2 id="static-public-members">Static Public Members</h2> <div class="table"><table class="alignedsummary"> <tr><td class="memItemLeft rightAlign topAlign"> const QMetaObject </td><td class="memItemRight bottomAlign"><b><a href="qtcpserver.html#staticMetaObject-var">staticMetaObject</a></b></td></tr> </table></div> <ul> <li class="fn">9 static public members inherited from <a href="../qtcore/qobject.html#static-public-members">QObject</a></li> </ul> <a name="protected-functions"></a> <h2 id="protected-functions">Protected Functions</h2> <div class="table"><table class="alignedsummary"> <tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qtcpserver.html#addPendingConnection">addPendingConnection</a></b>(QTcpSocket *<i>socket</i>)</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> virtual void </td><td class="memItemRight bottomAlign"><b><a href="qtcpserver.html#incomingConnection">incomingConnection</a></b>(qintptr <i>socketDescriptor</i>)</td></tr> </table></div> <ul> <li class="fn">9 protected functions inherited from <a href="../qtcore/qobject.html#protected-functions">QObject</a></li> </ul> <h3>Additional Inherited Members</h3> <ul> <li class="fn">1 property inherited from <a href="../qtcore/qobject.html#properties">QObject</a></li> <li class="fn">1 public slot inherited from <a href="../qtcore/qobject.html#public-slots">QObject</a></li> </ul> <a name="details"></a> <!-- $$$QTcpServer-description --> <div class="descr"> <h2 id="details">Detailed Description</h2> <p>The <a href="qtcpserver.html">QTcpServer</a> class provides a TCP-based server.</p> <p>This class makes it possible to accept incoming TCP connections. You can specify the port or have <a href="qtcpserver.html">QTcpServer</a> pick one automatically. You can listen on a specific address or on all the machine's addresses.</p> <p>Call <a href="qtcpserver.html#listen">listen</a>() to have the server listen for incoming connections. The <a href="qtcpserver.html#newConnection">newConnection</a>() signal is then emitted each time a client connects to the server.</p> <p>Call <a href="qtcpserver.html#nextPendingConnection">nextPendingConnection</a>() to accept the pending connection as a connected <a href="qtcpsocket.html">QTcpSocket</a>. The function returns a pointer to a <a href="qtcpsocket.html">QTcpSocket</a> in <a href="qabstractsocket.html#SocketState-enum">QAbstractSocket::ConnectedState</a> that you can use for communicating with the client.</p> <p>If an error occurs, <a href="qtcpserver.html#serverError">serverError</a>() returns the type of error, and <a href="qtcpserver.html#errorString">errorString</a>() can be called to get a human readable description of what happened.</p> <p>When listening for connections, the address and port on which the server is listening are available as <a href="qtcpserver.html#serverAddress">serverAddress</a>() and <a href="qtcpserver.html#serverPort">serverPort</a>().</p> <p>Calling <a href="qtcpserver.html#close">close</a>() makes <a href="qtcpserver.html">QTcpServer</a> stop listening for incoming connections.</p> <p>Although <a href="qtcpserver.html">QTcpServer</a> is mostly designed for use with an event loop, it's possible to use it without one. In that case, you must use <a href="qtcpserver.html#waitForNewConnection">waitForNewConnection</a>(), which blocks until either a connection is available or a timeout expires.</p> </div> <p><b>See also </b><a href="qtcpsocket.html">QTcpSocket</a>, <a href="qtnetwork-fortuneserver-example.html">Fortune Server Example</a>, <a href="qtnetwork-threadedfortuneserver-example.html">Threaded Fortune Server Example</a>, <a href="qtnetwork-loopback-example.html">Loopback Example</a>, and <a href="qtnetwork-torrent-example.html">Torrent Example</a>.</p> <!-- @@@QTcpServer --> <div class="func"> <h2>Member Function Documentation</h2> <!-- $$$QTcpServer[overload1]$$$QTcpServerQObject* --> <h3 class="fn" id="QTcpServer"><a name="QTcpServer"></a>QTcpServer::<span class="name">QTcpServer</span>(<span class="type"><a href="../qtcore/qobject.html#QObject">QObject</a></span> *<i>parent</i> = nullptr)</h3> <p>Constructs a <a href="qtcpserver.html">QTcpServer</a> object.</p> <p><i>parent</i> is passed to the <a href="../qtcore/qobject.html">QObject</a> constructor.</p> <p><b>See also </b><a href="qtcpserver.html#listen">listen</a>() and <a href="qtcpserver.html#setSocketDescriptor">setSocketDescriptor</a>().</p> <!-- @@@QTcpServer --> <!-- $$$~QTcpServer[overload1]$$$~QTcpServer --> <h3 class="fn" id="dtor.QTcpServer"><a name="dtor.QTcpServer"></a><code>[virtual] </code>QTcpServer::<span class="name">~QTcpServer</span>()</h3> <p>Destroys the <a href="qtcpserver.html">QTcpServer</a> object. If the server is listening for connections, the socket is automatically closed.</p> <p>Any client <a href="qtcpsocket.html">QTcpSocket</a>s that are still connected must either disconnect or be reparented before the server is deleted.</p> <p><b>See also </b><a href="qtcpserver.html#close">close</a>().</p> <!-- @@@~QTcpServer --> <!-- $$$acceptError[overload1]$$$acceptErrorQAbstractSocket::SocketError --> <h3 class="fn" id="acceptError"><a name="acceptError"></a><code>[signal] </code><span class="type">void</span> QTcpServer::<span class="name">acceptError</span>(<span class="type"><a href="qabstractsocket.html#SocketError-enum">QAbstractSocket::SocketError</a></span> <i>socketError</i>)</h3> <p>This signal is emitted when accepting a new connection results in an error. The <i>socketError</i> parameter describes the type of error that occurred.</p> <p>This function was introduced in Qt 5.0.</p> <p><b>See also </b><a href="qtcpserver.html#pauseAccepting">pauseAccepting</a>() and <a href="qtcpserver.html#resumeAccepting">resumeAccepting</a>().</p> <!-- @@@acceptError --> <!-- $$$addPendingConnection[overload1]$$$addPendingConnectionQTcpSocket* --> <h3 class="fn" id="addPendingConnection"><a name="addPendingConnection"></a><code>[protected] </code><span class="type">void</span> QTcpServer::<span class="name">addPendingConnection</span>(<span class="type"><a href="qtcpsocket.html">QTcpSocket</a></span> *<i>socket</i>)</h3> <p>This function is called by <a href="qtcpserver.html#incomingConnection">QTcpServer::incomingConnection</a>() to add the <i>socket</i> to the list of pending incoming connections.</p> <p><b>Note: </b>Don't forget to call this member from reimplemented <a href="qtcpserver.html#incomingConnection">incomingConnection</a>() if you do not want to break the Pending Connections mechanism.</p><p>This function was introduced in Qt 4.7.</p> <p><b>See also </b><a href="qtcpserver.html#incomingConnection">incomingConnection</a>().</p> <!-- @@@addPendingConnection --> <!-- $$$close[overload1]$$$close --> <h3 class="fn" id="close"><a name="close"></a><span class="type">void</span> QTcpServer::<span class="name">close</span>()</h3> <p>Closes the server. The server will no longer listen for incoming connections.</p> <p><b>See also </b><a href="qtcpserver.html#listen">listen</a>().</p> <!-- @@@close --> <!-- $$$errorString[overload1]$$$errorString --> <h3 class="fn" id="errorString"><a name="errorString"></a><span class="type"><a href="../qtcore/qstring.html">QString</a></span> QTcpServer::<span class="name">errorString</span>() const</h3> <p>Returns a human readable description of the last error that occurred.</p> <p><b>See also </b><a href="qtcpserver.html#serverError">serverError</a>().</p> <!-- @@@errorString --> <!-- $$$hasPendingConnections[overload1]$$$hasPendingConnections --> <h3 class="fn" id="hasPendingConnections"><a name="hasPendingConnections"></a><code>[virtual] </code><span class="type">bool</span> QTcpServer::<span class="name">hasPendingConnections</span>() const</h3> <p>Returns <code>true</code> if the server has a pending connection; otherwise returns <code>false</code>.</p> <p><b>See also </b><a href="qtcpserver.html#nextPendingConnection">nextPendingConnection</a>() and <a href="qtcpserver.html#setMaxPendingConnections">setMaxPendingConnections</a>().</p> <!-- @@@hasPendingConnections --> <!-- $$$incomingConnection[overload1]$$$incomingConnectionqintptr --> <h3 class="fn" id="incomingConnection"><a name="incomingConnection"></a><code>[virtual protected] </code><span class="type">void</span> QTcpServer::<span class="name">incomingConnection</span>(<span class="type"><a href="../qtcore/qtglobal.html#qintptr-typedef">qintptr</a></span> <i>socketDescriptor</i>)</h3> <p>This virtual function is called by <a href="qtcpserver.html">QTcpServer</a> when a new connection is available. The <i>socketDescriptor</i> argument is the native socket descriptor for the accepted connection.</p> <p>The base implementation creates a <a href="qtcpsocket.html">QTcpSocket</a>, sets the socket descriptor and then stores the <a href="qtcpsocket.html">QTcpSocket</a> in an internal list of pending connections. Finally <a href="qtcpserver.html#newConnection">newConnection</a>() is emitted.</p> <p>Reimplement this function to alter the server's behavior when a connection is available.</p> <p>If this server is using <a href="qnetworkproxy.html">QNetworkProxy</a> then the <i>socketDescriptor</i> may not be usable with native socket functions, and should only be used with <a href="qabstractsocket.html#setSocketDescriptor">QTcpSocket::setSocketDescriptor</a>().</p> <p><b>Note: </b>If another socket is created in the reimplementation of this method, it needs to be added to the Pending Connections mechanism by calling <a href="qtcpserver.html#addPendingConnection">addPendingConnection</a>().</p><p><b>Note: </b>If you want to handle an incoming connection as a new <a href="qtcpsocket.html">QTcpSocket</a> object in another thread you have to pass the <a href="qtcpserver.html#socketDescriptor">socketDescriptor</a> to the other thread and create the <a href="qtcpsocket.html">QTcpSocket</a> object there and use its <a href="qtcpserver.html#setSocketDescriptor">setSocketDescriptor</a>() method.</p><p><b>See also </b><a href="qtcpserver.html#newConnection">newConnection</a>(), <a href="qtcpserver.html#nextPendingConnection">nextPendingConnection</a>(), and <a href="qtcpserver.html#addPendingConnection">addPendingConnection</a>().</p> <!-- @@@incomingConnection --> <!-- $$$isListening[overload1]$$$isListening --> <h3 class="fn" id="isListening"><a name="isListening"></a><span class="type">bool</span> QTcpServer::<span class="name">isListening</span>() const</h3> <p>Returns <code>true</code> if the server is currently listening for incoming connections; otherwise returns <code>false</code>.</p> <p><b>See also </b><a href="qtcpserver.html#listen">listen</a>().</p> <!-- @@@isListening --> <!-- $$$listen[overload1]$$$listenconstQHostAddress&quint16 --> <h3 class="fn" id="listen"><a name="listen"></a><span class="type">bool</span> QTcpServer::<span class="name">listen</span>(const <span class="type"><a href="qhostaddress.html">QHostAddress</a></span> &<i>address</i> = QHostAddress::Any, <span class="type"><a href="../qtcore/qtglobal.html#quint16-typedef">quint16</a></span> <i>port</i> = 0)</h3> <p>Tells the server to listen for incoming connections on address <i>address</i> and port <i>port</i>. If <i>port</i> is 0, a port is chosen automatically. If <i>address</i> is <a href="qhostaddress.html#SpecialAddress-enum">QHostAddress::Any</a>, the server will listen on all network interfaces.</p> <p>Returns <code>true</code> on success; otherwise returns <code>false</code>.</p> <p><b>See also </b><a href="qtcpserver.html#isListening">isListening</a>().</p> <!-- @@@listen --> <!-- $$$maxPendingConnections[overload1]$$$maxPendingConnections --> <h3 class="fn" id="maxPendingConnections"><a name="maxPendingConnections"></a><span class="type">int</span> QTcpServer::<span class="name">maxPendingConnections</span>() const</h3> <p>Returns the maximum number of pending accepted connections. The default is 30.</p> <p><b>See also </b><a href="qtcpserver.html#setMaxPendingConnections">setMaxPendingConnections</a>() and <a href="qtcpserver.html#hasPendingConnections">hasPendingConnections</a>().</p> <!-- @@@maxPendingConnections --> <!-- $$$newConnection[overload1]$$$newConnection --> <h3 class="fn" id="newConnection"><a name="newConnection"></a><code>[signal] </code><span class="type">void</span> QTcpServer::<span class="name">newConnection</span>()</h3> <p>This signal is emitted every time a new connection is available.</p> <p><b>See also </b><a href="qtcpserver.html#hasPendingConnections">hasPendingConnections</a>() and <a href="qtcpserver.html#nextPendingConnection">nextPendingConnection</a>().</p> <!-- @@@newConnection --> <!-- $$$nextPendingConnection[overload1]$$$nextPendingConnection --> <h3 class="fn" id="nextPendingConnection"><a name="nextPendingConnection"></a><code>[virtual] </code><span class="type"><a href="qtcpsocket.html">QTcpSocket</a></span> *QTcpServer::<span class="name">nextPendingConnection</span>()</h3> <p>Returns the next pending connection as a connected <a href="qtcpsocket.html">QTcpSocket</a> object.</p> <p>The socket is created as a child of the server, which means that it is automatically deleted when the <a href="qtcpserver.html">QTcpServer</a> object is destroyed. It is still a good idea to delete the object explicitly when you are done with it, to avoid wasting memory.</p> <p>0 is returned if this function is called when there are no pending connections.</p> <p><b>Note: </b>The returned <a href="qtcpsocket.html">QTcpSocket</a> object cannot be used from another thread. If you want to use an incoming connection from another thread, you need to override <a href="qtcpserver.html#incomingConnection">incomingConnection</a>().</p><p><b>See also </b><a href="qtcpserver.html#hasPendingConnections">hasPendingConnections</a>().</p> <!-- @@@nextPendingConnection --> <!-- $$$pauseAccepting[overload1]$$$pauseAccepting --> <h3 class="fn" id="pauseAccepting"><a name="pauseAccepting"></a><span class="type">void</span> QTcpServer::<span class="name">pauseAccepting</span>()</h3> <p>Pauses accepting new connections. Queued connections will remain in queue.</p> <p>This function was introduced in Qt 5.0.</p> <p><b>See also </b><a href="qtcpserver.html#resumeAccepting">resumeAccepting</a>().</p> <!-- @@@pauseAccepting --> <!-- $$$proxy[overload1]$$$proxy --> <h3 class="fn" id="proxy"><a name="proxy"></a><span class="type"><a href="qnetworkproxy.html">QNetworkProxy</a></span> QTcpServer::<span class="name">proxy</span>() const</h3> <p>Returns the network proxy for this socket. By default <a href="qnetworkproxy.html#ProxyType-enum">QNetworkProxy::DefaultProxy</a> is used.</p> <p>This function was introduced in Qt 4.1.</p> <p><b>See also </b><a href="qtcpserver.html#setProxy">setProxy</a>() and <a href="qnetworkproxy.html">QNetworkProxy</a>.</p> <!-- @@@proxy --> <!-- $$$resumeAccepting[overload1]$$$resumeAccepting --> <h3 class="fn" id="resumeAccepting"><a name="resumeAccepting"></a><span class="type">void</span> QTcpServer::<span class="name">resumeAccepting</span>()</h3> <p>Resumes accepting new connections.</p> <p>This function was introduced in Qt 5.0.</p> <p><b>See also </b><a href="qtcpserver.html#pauseAccepting">pauseAccepting</a>().</p> <!-- @@@resumeAccepting --> <!-- $$$serverAddress[overload1]$$$serverAddress --> <h3 class="fn" id="serverAddress"><a name="serverAddress"></a><span class="type"><a href="qhostaddress.html">QHostAddress</a></span> QTcpServer::<span class="name">serverAddress</span>() const</h3> <p>Returns the server's address if the server is listening for connections; otherwise returns <a href="qhostaddress.html#SpecialAddress-enum">QHostAddress::Null</a>.</p> <p><b>See also </b><a href="qtcpserver.html#serverPort">serverPort</a>() and <a href="qtcpserver.html#listen">listen</a>().</p> <!-- @@@serverAddress --> <!-- $$$serverError[overload1]$$$serverError --> <h3 class="fn" id="serverError"><a name="serverError"></a><span class="type"><a href="qabstractsocket.html#SocketError-enum">QAbstractSocket::SocketError</a></span> QTcpServer::<span class="name">serverError</span>() const</h3> <p>Returns an error code for the last error that occurred.</p> <p><b>See also </b><a href="qtcpserver.html#errorString">errorString</a>().</p> <!-- @@@serverError --> <!-- $$$serverPort[overload1]$$$serverPort --> <h3 class="fn" id="serverPort"><a name="serverPort"></a><span class="type"><a href="../qtcore/qtglobal.html#quint16-typedef">quint16</a></span> QTcpServer::<span class="name">serverPort</span>() const</h3> <p>Returns the server's port if the server is listening for connections; otherwise returns 0.</p> <p><b>See also </b><a href="qtcpserver.html#serverAddress">serverAddress</a>() and <a href="qtcpserver.html#listen">listen</a>().</p> <!-- @@@serverPort --> <!-- $$$setMaxPendingConnections[overload1]$$$setMaxPendingConnectionsint --> <h3 class="fn" id="setMaxPendingConnections"><a name="setMaxPendingConnections"></a><span class="type">void</span> QTcpServer::<span class="name">setMaxPendingConnections</span>(<span class="type">int</span> <i>numConnections</i>)</h3> <p>Sets the maximum number of pending accepted connections to <i>numConnections</i>. <a href="qtcpserver.html">QTcpServer</a> will accept no more than <i>numConnections</i> incoming connections before <a href="qtcpserver.html#nextPendingConnection">nextPendingConnection</a>() is called. By default, the limit is 30 pending connections.</p> <p>Clients may still able to connect after the server has reached its maximum number of pending connections (i.e., <a href="qtcpsocket.html">QTcpSocket</a> can still emit the connected() signal). <a href="qtcpserver.html">QTcpServer</a> will stop accepting the new connections, but the operating system may still keep them in queue.</p> <p><b>See also </b><a href="qtcpserver.html#maxPendingConnections">maxPendingConnections</a>() and <a href="qtcpserver.html#hasPendingConnections">hasPendingConnections</a>().</p> <!-- @@@setMaxPendingConnections --> <!-- $$$setProxy[overload1]$$$setProxyconstQNetworkProxy& --> <h3 class="fn" id="setProxy"><a name="setProxy"></a><span class="type">void</span> QTcpServer::<span class="name">setProxy</span>(const <span class="type"><a href="qnetworkproxy.html">QNetworkProxy</a></span> &<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 class="cpp"> server<span class="operator">-</span><span class="operator">></span>setProxy(<span class="type"><a href="qnetworkproxy.html">QNetworkProxy</a></span><span class="operator">::</span>NoProxy); </pre> <p>This function was introduced in Qt 4.1.</p> <p><b>See also </b><a href="qtcpserver.html#proxy">proxy</a>() and <a href="qnetworkproxy.html">QNetworkProxy</a>.</p> <!-- @@@setProxy --> <!-- $$$setSocketDescriptor[overload1]$$$setSocketDescriptorqintptr --> <h3 class="fn" id="setSocketDescriptor"><a name="setSocketDescriptor"></a><span class="type">bool</span> QTcpServer::<span class="name">setSocketDescriptor</span>(<span class="type"><a href="../qtcore/qtglobal.html#qintptr-typedef">qintptr</a></span> <i>socketDescriptor</i>)</h3> <p>Sets the socket descriptor this server should use when listening for incoming connections to <i>socketDescriptor</i>. Returns <code>true</code> if the socket is set successfully; otherwise returns <code>false</code>.</p> <p>The socket is assumed to be in listening state.</p> <p><b>See also </b><a href="qtcpserver.html#socketDescriptor">socketDescriptor</a>() and <a href="qtcpserver.html#isListening">isListening</a>().</p> <!-- @@@setSocketDescriptor --> <!-- $$$socketDescriptor[overload1]$$$socketDescriptor --> <h3 class="fn" id="socketDescriptor"><a name="socketDescriptor"></a><span class="type"><a href="../qtcore/qtglobal.html#qintptr-typedef">qintptr</a></span> QTcpServer::<span class="name">socketDescriptor</span>() const</h3> <p>Returns the native socket descriptor the server uses to listen for incoming instructions, or -1 if the server is not listening.</p> <p>If the server is using <a href="qnetworkproxy.html">QNetworkProxy</a>, the returned descriptor may not be usable with native socket functions.</p> <p><b>See also </b><a href="qtcpserver.html#setSocketDescriptor">setSocketDescriptor</a>() and <a href="qtcpserver.html#isListening">isListening</a>().</p> <!-- @@@socketDescriptor --> <!-- $$$waitForNewConnection[overload1]$$$waitForNewConnectionintbool* --> <h3 class="fn" id="waitForNewConnection"><a name="waitForNewConnection"></a><span class="type">bool</span> QTcpServer::<span class="name">waitForNewConnection</span>(<span class="type">int</span> <i>msec</i> = 0, <span class="type">bool</span> *<i>timedOut</i> = nullptr)</h3> <p>Waits for at most <i>msec</i> milliseconds or until an incoming connection is available. Returns <code>true</code> if a connection is available; otherwise returns <code>false</code>. If the operation timed out and <i>timedOut</i> is not 0, *<i>timedOut</i> will be set to true.</p> <p>This is a blocking function call. Its use is disadvised in a single-threaded GUI application, since the whole application will stop responding until the function returns. waitForNewConnection() is mostly useful when there is no event loop available.</p> <p>The non-blocking alternative is to connect to the <a href="qtcpserver.html#newConnection">newConnection</a>() signal.</p> <p>If msec is -1, this function will not time out.</p> <p><b>See also </b><a href="qtcpserver.html#hasPendingConnections">hasPendingConnections</a>() and <a href="qtcpserver.html#nextPendingConnection">nextPendingConnection</a>().</p> <!-- @@@waitForNewConnection --> </div> </div> </div> </div> </div> </div> <div class="footer"> <p> <acronym title="Copyright">©</acronym> 2019 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners.<br/> The documentation provided herein is licensed under the terms of the <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation License version 1.3</a> as published by the Free Software Foundation.<br/> Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners. </p> </div> </body> </html>