Home | All Classes | Main Classes | Annotated | Grouped Classes | Functions

QServerSocket Class Reference

The QServerSocket class provides a TCP-based server. More...

#include <QServerSocket>

Inherits QObject.

Inherited by QWSServer.

List of all members.

Writable Properties

Public Functions

Public Slots

Signals

Static Public Members

Protected Functions


Detailed Description

The QServerSocket class provides a TCP-based server.

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

Using the API is very simple: subclass QServerSocket, 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 )

Construct an empty server socket with the given parent.

This constructor, in combination with setSocket(), allows us to use the QServerSocket class as a wrapper for other socket types, such as Unix Domain Sockets.

See also setSocket().

QServerSocket::QServerSocket ( Q_UINT16 port, int backlog = 1, QObject * parent = 0 )

Creates a server socket object to serve the given port on all the addresses of this host. If port is 0, QServerSocket will pick a suitable port in a system-dependent manner. Use backlog to specify how many pending connections the server can have.

The parent argument is passed on 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 = 1, QObject * parent = 0 )

Creates a server socket object to serve the given port only on the given address. Use backlog to specify how many pending connections the server can have.

The parent argument is passed on 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]

Destroys the socket.

All backlogged connections are closed; this includes connections that have reached the host, but have not yet been set up by a call to QSocketDevice::accept().

Existing connections continue to exist; this only affects the ability of the server to accept 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 )   [pure virtual]

This pure virtual function is responsible for setting up a new incoming connection. The socket given is the fd (file descriptor) for the newly accepted connection.

bool QServerSocket::ok () const

Returns true if the socket is ready to use; otherwise returns false.

Q_UINT16 QServerSocket::port () const

Returns the port number on which this server socket listens. This is always non-zero; if you specify 0 in the constructor, QServerSocket will pick a non-zero port itself. ok() must be true before this function is called.

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

void QServerSocket::setSocket ( int socket )   [virtual]

Sets the socket to use for the server. bind() and listen() should already have been called for the socket given.

This allows us to use the QServerSocket class as a wrapper for other socket types, such as Unix Domain Sockets.

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 0 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.


Copyright © 2004 Trolltech. Trademarks
Qt 4.0.0-tp1