Viadeo Twitter Google Bookmarks ! Facebook Digg del.icio.us MySpace Yahoo MyWeb Blinklist Netvouz Reddit Simpy StumbleUpon Bookmarks Windows Live Favorites 
Logo Documentation Qt ·  Page d'accueil  ·  Toutes les classes  ·  Classes principales  ·  Annotées  ·  Classes groupées  ·  Fonctions  · 

QServerSocket Class Reference
[network module]

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

#include <qserversocket.h>

Inherits QObject.

List of all member functions.

Public Members

  • QServerSocket ( Q_UINT16 port, int backlog = 1, QObject * parent = 0, const char * name = 0 )
  • QServerSocket ( const QHostAddress & address, Q_UINT16 port, int backlog = 1, 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 ) = 0

Protected Members


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, QSocketNotifier, and Input/Output and Networking.


Member Function Documentation

QServerSocket::QServerSocket ( 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, 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 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.

QServerSocket::QServerSocket ( 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.

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

Construct an empty server socket.

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

QServerSocket::~QServerSocket () [virtual]

Destroys the socket.

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

Existing connections continue to exist; this only affects the 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 ) [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 QServerSocket::ok () const

Returns TRUE if the construction succeeded; 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 calling this function.

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

Example: network/httpd/httpd.cpp.

void QServerSocket::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 QServerSocket class as a wrapper for other socket types (e.g. 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.


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

Publicité

Best Of

Actualités les plus lues

Semaine
Mois
Année
  1. « Quelque chose ne va vraiment pas avec les développeurs "modernes" », un développeur à "l'ancienne" critique la multiplication des bibliothèques 69
  2. Apercevoir la troisième dimension ou l'utilisation multithreadée d'OpenGL dans Qt, un article des Qt Quarterly traduit par Guillaume Belz 0
  3. Les développeurs ignorent-ils trop les failles découvertes dans leur code ? Prenez-vous en compte les remarques des autres ? 17
  4. BlackBerry 10 : premières images du prochain OS de RIM qui devrait intégrer des widgets et des tuiles inspirées de Windows Phone 0
  5. Quelles nouveautés de C++11 Visual C++ doit-il rapidement intégrer ? Donnez-nous votre avis 10
  6. Adieu qmake, bienvenue qbs : Qt Building Suite, un outil déclaratif et extensible pour la compilation de projets Qt 17
  7. La rubrique PyQt/PySide a besoin de vous ! 0
Page suivante

Le Qt Quarterly au hasard

Logo

Un tr() oublié ?

Qt Quarterly est la revue trimestrielle proposée par Nokia et à destination des développeurs Qt. Ces articles d'une grande qualité technique sont rédigés par des experts Qt. Lire l'article.

Communauté

Ressources

Liens utiles

Contact

  • Vous souhaitez rejoindre la rédaction ou proposer un tutoriel, une traduction, une question... ? Postez dans le forum Contribuez ou contactez-nous par MP ou par email (voir en bas de page).

Qt dans le magazine

Cette page est une traduction d'une page de la documentation de Qt, écrite par Nokia Corporation and/or its subsidiary(-ies). Les éventuels problèmes résultant d'une mauvaise traduction ne sont pas imputables à Nokia. Qt 3.3
Copyright © 2012 Developpez LLC. Tous droits réservés Developpez LLC. Aucune reproduction, même partielle, ne peut être faite de ce site et de l'ensemble de son contenu : textes, documents et images sans l'autorisation expresse de Developpez LLC. Sinon, vous encourez selon la loi jusqu'à 3 ans de prison et jusqu'à 300 000 E de dommages et intérêts. Cette page est déposée à la SACD.
Vous avez déniché une erreur ? Un bug ? Une redirection cassée ? Ou tout autre problème, quel qu'il soit ? Ou bien vous désirez participer à ce projet de traduction ? N'hésitez pas à nous contacter ou par MP !
 
 
 
 
Partenaires

Hébergement Web