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

# TQServerSocket Class Reference
[network module]

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

`#include <ntqserversocket.h>`

Inherits TQObject.

List of all member functions.

## Public Members

- TQServerSocket ( TQ_UINT16 port, int backlog = 1, TQObject * parent = 0, const char * name = 0 )
- TQServerSocket ( const TQHostAddress & address, TQ_UINT16 port, int backlog = 1, TQObject * parent = 0, const char * name = 0 )
- TQServerSocket ( TQObject * parent = 0, const char * name = 0 )
- virtual ~TQServerSocket ()
- bool ok () const
- TQ_UINT16 port () const
- int socket () const
- virtual void setSocket ( int socket )
- TQHostAddress address () const
- virtual void newConnection ( int socket ) = 0

## Protected Members

- TQSocketDevice * socketDevice ()

## Detailed Description

The TQServerSocket class provides a TCP-based server.

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

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

See also TQSocket, TQSocketDevice, TQHostAddress, TQSocketNotifier, and Input/Output and Networking.

## Member Function Documentation

### TQServerSocket::TQServerSocket ( TQ_UINT16 port, int backlog = 1, TQObject * 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, TQServerSocket 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 TQObject 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.

### TQServerSocket::TQServerSocket ( const TQHostAddress & address, TQ_UINT16 port, int backlog = 1, TQObject * 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 TQObject 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.

### TQServerSocket::TQServerSocket ( TQObject * parent = 0, const char * name = 0 )

Construct an empty server socket.

This constructor, in combination with setSocket(), allows us to use the TQServerSocket 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 TQObject constructor.

See also setSocket().

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

Destroys the socket.

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

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

### TQHostAddress TQServerSocket::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 TQSocketDevice::address().

### void TQServerSocket::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 TQServerSocket::ok () const

Returns TRUE if the construction succeeded; otherwise returns FALSE.

### TQ_UINT16 TQServerSocket::port () const

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

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

Example: network/httpd/httpd.cpp.

### void TQServerSocket::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 TQServerSocket class as a wrapper for other socket types (e.g. Unix Domain Sockets).

### int TQServerSocket::socket () const

Returns the operating system socket.

### TQSocketDevice * TQServerSocket::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.

This file is part of the TQt toolkit. Copyright © 1995-2007 Trolltech. All Rights Reserved.