Qt 4.8: Q3ServerSocket Class Reference

Qt Reference Documentation

# Q3ServerSocket Class Reference

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

     #include <Q3ServerSocket>

This class is part of the Qt 3 support library. It is provided to keep old source code working. We strongly advise against using it in new code. See Porting to Qt 4 for more information.

Inherits: QObject.

- List of all members, including inherited members

## Public Functions

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

- 29 public functions inherited from QObject

## Protected Functions

Q3SocketDevice * | socketDevice ()

- 8 protected functions inherited from QObject

### Additional Inherited Members

- 1 property inherited from QObject
- 1 public slot inherited from QObject
- 1 signal inherited from QObject
- 7 static public members inherited from QObject

## Detailed Description

The Q3ServerSocket class provides a TCP-based server.

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

Using the API is very simple: subclass Q3ServerSocket, 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, Q3ServerSocket cannot accept or reject connections conditionally.)

See also Q3Socket, Q3SocketDevice, QHostAddress, and QSocketNotifier.

## Member Function Documentation

### Q3ServerSocket::Q3ServerSocket ( Q_UINT16 port, int backlog = 1, 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, Q3ServerSocket will pick a suitable port in a system-dependent manner. Use backlog to specify how many pending connections the server can have.

The parent and name arguments are 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.

### Q3ServerSocket::Q3ServerSocket ( const QHostAddress & address, Q_UINT16 port, int backlog = 1, QObject * parent = 0, const char * name = 0 )

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

The parent and name arguments are 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.

### Q3ServerSocket::Q3ServerSocket ( QObject * parent = 0, const char * name = 0 )

Construct an empty server socket.

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

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

See also setSocket().

### Q3ServerSocket::~Q3ServerSocket ()`[virtual]`

Destroys the socket.

This causes any backlogged connections (connections that have reached the host, but not yet been completely set up by calling Q3SocketDevice::accept()) to be severed.

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

### QHostAddress Q3ServerSocket::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 Q3SocketDevice::address().

### void Q3ServerSocket::newConnection ( int socket )`[pure virtual]`

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

### bool Q3ServerSocket::ok () const

Returns true if the construction succeeded; otherwise returns false.

### Q_UINT16 Q3ServerSocket::port () const

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

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

### void Q3ServerSocket::setSocket ( int socket )`[virtual]`

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

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

See also socket().

### int Q3ServerSocket::socket () const

Returns the operating system socket.

See also setSocket().

### Q3SocketDevice * Q3ServerSocket::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.