<class name="QTcpServer" doc="/** <p>The <a href="QTcpServer.html#QTcpServer(com.trolltech.qt.core.QObject)"><tt>QTcpServer</tt></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(com.trolltech.qt.core.QObject)"><tt>QTcpServer</tt></a> pick one automatically. You can listen on a specific address or on all the machine's addresses.</p> <p>Call listen() to have the server listen for incoming connections. The <a href="QTcpServer.html#newConnection()"><tt>newConnection</tt></a> signal is then emitted each time a client connects to the server.</p> <p>Call <a href="QTcpServer.html#nextPendingConnection()"><tt>nextPendingConnection</tt></a> to accept the pending connection as a connected <a href="QTcpSocket.html"><tt>QTcpSocket</tt></a>. The function returns a pointer to a <a href="QTcpSocket.html"><tt>QTcpSocket</tt></a> in QAbstractSocket::ConnectedState that you can use for communicating with the client.</p> <p>If an error occurs, <a href="QTcpServer.html#serverError()"><tt>serverError</tt></a> returns the type of error, and <a href="QTcpServer.html#errorString()"><tt>errorString</tt></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()"><tt>serverAddress</tt></a> and serverPort().</p> <p>Calling <a href="QTcpServer.html#close()"><tt>close</tt></a> makes <a href="QTcpServer.html#QTcpServer(com.trolltech.qt.core.QObject)"><tt>QTcpServer</tt></a> stop listening for incoming connections.</p> <p>Although <a href="QTcpServer.html#QTcpServer(com.trolltech.qt.core.QObject)"><tt>QTcpServer</tt></a> is mostly designed for use with an event loop, it's possible to use it without one. In that case, you must use waitForNewConnection(), which blocks until either a connection is available or a timeout expires.</p> @see <a href="QTcpSocket.html"><tt>QTcpSocket</tt></a> @see Fortune Server Example</tt> @see Threaded Fortune Server Example</tt> @see Loopback Example</tt> @see Torrent Example</tt> */"> <signal name="protected final void newConnection()" doc="/** <p>This signal is emitted every time a new connection is available.</p> <dl> <dt><b>Compatible Slot Signature:</b></dt> <dd><tt>void mySlot()</tt></dd> </dl> <dl> <dt><b>See Also:</b></dt> <dd><a href="QTcpServer.html#hasPendingConnections()"><tt>hasPendingConnections</tt></a>, <a href="QTcpServer.html#nextPendingConnection()"><tt>nextPendingConnection</tt></a></dd> </dl> */"/> <method name="public QTcpServer(com.trolltech.qt.core.QObject parent)" doc="/** <p>Constructs a <a href="QTcpServer.html#QTcpServer(com.trolltech.qt.core.QObject)"><tt>QTcpServer</tt></a> object.</p> <p><tt>parent</tt> is passed to the <a href="%2E%2E/core/%2E%2E/core/QObject.html#QObject(com.trolltech.qt.core.QObject)"><tt>QObject</tt></a> constructor.</p> @see <tt>listen</tt> @see <a href="QTcpServer.html#setSocketDescriptor(int)"><tt>setSocketDescriptor</tt></a> */"/> <method name="public QTcpServer()" doc="/** <p>Equivalent to <a href="QTcpServer.html#QTcpServer(com.trolltech.qt.core.QObject)"><tt>QTcpServer</tt></a>(0). */"/> <method name="public final void close()" doc="/** <p>Closes the server. The server will no longer listen for incoming connections.</p> @see <tt>listen</tt> */"/> <method name="public final java.lang.String errorString()" doc="/** <p>Returns a human readable description of the last error that occurred.</p> @see <a href="QTcpServer.html#serverError()"><tt>serverError</tt></a> */"/> <method name="public final boolean isListening()" doc="/** <p>Returns true if the server is currently listening for incoming connections; otherwise returns false.</p> @see <tt>listen</tt> */"/> <method name="public final int maxPendingConnections()" doc="/** <p>Returns the maximum number of pending accepted connections. The default is 30.</p> @see <a href="QTcpServer.html#setMaxPendingConnections(int)"><tt>setMaxPendingConnections</tt></a> @see <a href="QTcpServer.html#hasPendingConnections()"><tt>hasPendingConnections</tt></a> */"/> <method name="public final com.trolltech.qt.network.QNetworkProxy proxy()" doc="/** <p>Returns the network proxy for this socket. By default QNetworkProxy::DefaultProxy is used.</p> @see <a href="QTcpServer.html#setProxy(com.trolltech.qt.network.QNetworkProxy)"><tt>setProxy</tt></a> @see <a href="QNetworkProxy.html"><tt>QNetworkProxy</tt></a> */"/> <method name="public final com.trolltech.qt.network.QHostAddress serverAddress()" doc="/** <p>Returns the server's address if the server is listening for connections; otherwise returns QHostAddress::Null.</p> @see <tt>serverPort</tt> @see <tt>listen</tt> */"/> <method name="public final com.trolltech.qt.network.QAbstractSocket.SocketError serverError()" doc="/** <p>Returns an error code for the last error that occurred.</p> @see <a href="QTcpServer.html#errorString()"><tt>errorString</tt></a> */"/> <method name="public final void setMaxPendingConnections(int numConnections)" doc="/** <p>Sets the maximum number of pending accepted connections to <tt>numConnections</tt>. <a href="QTcpServer.html#QTcpServer(com.trolltech.qt.core.QObject)"><tt>QTcpServer</tt></a> will accept no more than <tt>numConnections</tt> incoming connections before <a href="QTcpServer.html#nextPendingConnection()"><tt>nextPendingConnection</tt></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&#x2e;, <a href="QTcpSocket.html"><tt>QTcpSocket</tt></a> can still emit the connected() signal). <a href="QTcpServer.html#QTcpServer(com.trolltech.qt.core.QObject)"><tt>QTcpServer</tt></a> will stop accepting the new connections, but the operating system may still keep them in queue.</p> @see <a href="QTcpServer.html#maxPendingConnections()"><tt>maxPendingConnections</tt></a> @see <a href="QTcpServer.html#hasPendingConnections()"><tt>hasPendingConnections</tt></a> */"/> <method name="public final void setProxy(com.trolltech.qt.network.QNetworkProxy networkProxy)" doc="/** <p>Sets the explicit network proxy for this socket to <tt>networkProxy</tt>.</p> <p>To disable the use of a proxy for this socket, use the QNetworkProxy::NoProxy proxy type:</p> <pre> server-&gt;setProxy(QNetworkProxy::NoProxy);</pre> @see <a href="QTcpServer.html#proxy()"><tt>proxy</tt></a> @see <a href="QNetworkProxy.html"><tt>QNetworkProxy</tt></a> */"/> <method name="public final boolean setSocketDescriptor(int socketDescriptor)" doc="/** <p>Sets the socket descriptor this server should use when listening for incoming connections to <tt>socketDescriptor</tt>. Returns true if the socket is set successfully; otherwise returns false.</p> <p>The socket is assumed to be in listening state.</p> @see <a href="QTcpServer.html#socketDescriptor()"><tt>socketDescriptor</tt></a> @see <a href="QTcpServer.html#isListening()"><tt>isListening</tt></a> */"/> <method name="public final int socketDescriptor()" doc="/** <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"><tt>QNetworkProxy</tt></a>, the returned descriptor may not be usable with native socket functions.</p> @see <a href="QTcpServer.html#setSocketDescriptor(int)"><tt>setSocketDescriptor</tt></a> @see <a href="QTcpServer.html#isListening()"><tt>isListening</tt></a> */"/> <method name="public boolean hasPendingConnections()" doc="/** <p>Returns true if the server has a pending connection; otherwise returns false.</p> @see <a href="QTcpServer.html#nextPendingConnection()"><tt>nextPendingConnection</tt></a> @see <a href="QTcpServer.html#setMaxPendingConnections(int)"><tt>setMaxPendingConnections</tt></a> */"/> <method name="protected void incomingConnection(int handle)" doc="/** <p>This virtual function is called by <a href="QTcpServer.html#QTcpServer(com.trolltech.qt.core.QObject)"><tt>QTcpServer</tt></a> when a new connection is available. The <tt>handle</tt> argument is the native socket descriptor for the accepted connection.</p> <p>The base implementation creates a <a href="QTcpSocket.html"><tt>QTcpSocket</tt></a>, sets the socket descriptor and then stores the <a href="QTcpSocket.html"><tt>QTcpSocket</tt></a> in an internal list of pending connections. Finally <a href="QTcpServer.html#newConnection()"><tt>newConnection</tt></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"><tt>QNetworkProxy</tt></a> then the <tt>handle</tt> may not be usable with native socket functions, and should only be used with QTcpSocket::setSocketDescriptor().</p> @see <a href="QTcpServer.html#newConnection()"><tt>newConnection</tt></a> @see <a href="QTcpServer.html#nextPendingConnection()"><tt>nextPendingConnection</tt></a> */"/> <method name="public com.trolltech.qt.network.QTcpSocket nextPendingConnection()" doc="/** <p>Returns the next pending connection as a connected <a href="QTcpSocket.html"><tt>QTcpSocket</tt></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(com.trolltech.qt.core.QObject)"><tt>QTcpServer</tt></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> @see <a href="QTcpServer.html#hasPendingConnections()"><tt>hasPendingConnections</tt></a> */"/> </class>