QServerSocket(3qt)

NAME
QServerSocket - TCP-based server

#include <qserversocket.h>

Inherits QObject.

  Public Members
QServerSocket ( Q_UINT16 port, int backlog = 0, QObject * parent=0, const char * name=0 )
QServerSocket ( const QHostAddress & address, Q_UINT16 port, int backlog = 0, QObject * parent=0, const char * name=0 )
QServerSocket ( QObject * parent=0, const char * name=0 )
virtual ~QServerSocket ()
bool ok () const
Q_UINT16 port () const
int socket () const
virtual void setSocket ( int socket )
QHostAddress address () const
virtual void newConnection ( int socket )

  Protected Members
QSocketDevice* socketDevice ()

DESCRIPTION
The QServerSocket class provides a TCP-based server.

This class is a convenience class for accepting incoming TCP connections. You can specify port or have QSocketServer pick one, and listen on just one address or on all the addresses of the machine.

The API is very simple: Subclass it, call the constructor of your choice, and implement newConnection() to handle new incoming connections. There is nothing more to do.

(Note that due to lack of support in the underlying APIs, QServerSocket cannot accept or reject connections conditionally.)

See also QSocket, QSocketDevice, QHostAddress and QSocketNotifier.

MEMBER FUNCTION DOCUMENTATION

QServerSocket::QServerSocket ( QObject * parent=0, const char * name=0 )
Construct an empty server socket.

This constructor in combination with setSocket() allows one to use the QServerSocket class as a wrapper for other socket types (e.g. Unix Domain Sockets under Unix).

See also setSocket().

QServerSocket::QServerSocket ( Q_UINT16 port, int backlog = 0, QObject * parent=0, const char * name=0 )
Creates a server socket object, that will serve the given port on all the addresses of this host. If port is 0, QServerSocket picks a suitable port in in a system-dependent manner. With backlog you can specify how many pending connections a server can have.

The parent and name arguments are passed on as usual to the QObject constructor.

Warning: On Tru64 Unix systems a value of 0 for backlog means that you don't accept any connections at all; you should specify a value larger than 0.

QServerSocket::QServerSocket ( const QHostAddress & address, Q_UINT16 port, int backlog = 0, QObject * parent=0, const char * name=0 )
Creates a server socket object, that will serve the given port on just address. With backlog you can specify how many pending connections a server can have.

The parent and name arguments are passed on as usual to the QObject constructor.

Warning: On Tru64 Unix systems a value of 0 for backlog means that you don't accept any connections at all; you should specify a value larger than 0.

QServerSocket::~QServerSocket () [virtual]
Destructs the socket.

This brutally severes any backlogged connections (connections that have reached the host, but not yet been completely set up by calling QSocketDevice::accept()).

Existing connections continue to exist; this only affects acceptance of new connections.

QHostAddress QServerSocket::address () const
Returns the address on which this object listens, or 0.0.0.0 if this object listens on more than one address. ok() must be TRUE before calling this function.

See also port() and QSocketDevice::address().

void QServerSocket::newConnection ( int socket ) [virtual]
This pure virtual function is responsible for setting up a new incoming connection. socket is the fd of the newly accepted connection.

bool QServerSocket::ok () const
Tests that the construction succeeded.

Q_UINT16 QServerSocket::port () const
Returns the port number on which this object listens. This is always non-zero; if you specify 0 in the constructor, QServerSocket picks a port itself and port() returns its number. ok() must be TRUE before calling this function.

See also address() and QSocketDevice::port().

void QServerSocket::setSocket ( int socket ) [virtual]
Sets the socket to use socket. bind() and listen() should already be called For this socket.

This allows one to use the QServerSocket class as a wrapper for other socket types (e.g. Unix Domain Sockets under Unix).

int QServerSocket::socket () const
Returns the operating system socket.

QSocketDevice * QServerSocket::socketDevice () [protected]
Returns a pointer to the internal socket device. The returned pointer is null if there is no connection or pending connection.

There is normally no need to manipulate the socket device directly since this class does all the necessary setup for most client or server socket applications.

SEE ALSO
http://doc.trolltech.com/qserversocket.html http://www.trolltech.com/faq/tech.html

COPYRIGHT
Copyright 1992-2001 Trolltech AS, http://www.trolltech.com. See the license file included in the distribution for a complete license statement.

AUTHOR
Generated automatically from the source code.

BUGS
If you find a bug in Qt, please report it as described in http://doc.trolltech.com/bughowto.html. Good bug reports make our job much simpler. Thank you.

In case of content or formattting problems with this manual page, please report them to qt-bugs@trolltech.com. Please include the name of the manual page (qserversocket.3qt) and the Qt version (2.3.5).