QServerSocket(3qt)
π QServerSocket(3qt) π
okay bestie, welcome to QServerSocket(3qt) β yes it's a Qt 3 man page, yes it's giving vintage, and yes we're gonna make it make sense. sit down, grab a strawberry, let's go πβ¨
β¨ NAME β¨
QServerSocket β a TCP-based server, periodt π
πΈ SYNOPSIS πΈ
#include <qserversocket.h>
Inherits QObject. (yes she has a whole family tree, we love a lineage π)
π― 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 π«Ά
QSocketDevice * socketDevice ()
π¦ DESCRIPTION π¦
The QServerSocket class provides a TCP-based server. no cap, that's the whole vibe.
It's a convenience class for accepting incoming TCP connections. The way that you get to choose: you can specify the port, or you can let QServerSocket pick one for you. And you can listen on just one address, or on all the machine's addresses. your call, bestie, you're the main character here π
Using the API is literally so simple it's iconic:
- subclass
QServerSocket - call the constructor of your choice
- implement
newConnection()to handle new incoming connections
and that's it. there is nothing more to do. ate. π₯
ok important lil reality check: due to lack of support in the underlying APIs, QServerSocket cannot accept or reject connections conditionally. so no vibes-based gatekeeping at the socket level, sorry π
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 (mysterious! iconic! π§). 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 of0for backlog means you don't accept any connections at all. specify a value larger than0, bestie, don't do that to yourself π
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 of0for backlog means you don't accept any connections at all; you should specify a value larger than0. same warning, same energy, still true π«Ά
QServerSocket::QServerSocket ( QObject * parent = 0, const char * name = 0 )
Construct an empty server socket. like, a blank canvas, a fresh face card β¨
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). versatile queen π
The parent and name arguments are passed on to the QObject constructor.
See also setSocket().
QServerSocket::~QServerSocket () [virtual]
Destroys the socket. rip boo you had a good run π
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. so your current besties stay, it's just that no new ones get let in the door πͺ
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. check first, don't be messy π
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. this is THE one you have to implement, no skipping, it's mandatory bestie, it's giving homework but make it slay π₯
bool QServerSocket::ok () const
Returns TRUE if the construction succeeded; otherwise returns FALSE. vibe check for your socket π«Ά
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. yes again, ok() first, always, it's the rule π
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. like, do your prep work first bestie, don't show up uninvited πΈ
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. the raw one. the real one. the unfiltered one π
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. so check it before you dereference it, obviously π
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. she handles it, you relax π
π SEE ALSO π
π COPYRIGHT π
Copyright 1992-2007 Trolltech ASA, http://www.trolltech.com. See the license file included in the distribution for a complete license statement.
π AUTHOR π
Generated automatically from the source code. (no human wrote this, it just manifested, we respect the grind β¨)
π BUGS π
If you find a bug in Qt, please report it as described in http://doc.trolltech.com/bughowto.html. Good bug reports help us to help you. Thank you. (they're being so polite about it and honestly? valid π«Ά)
The definitive Qt documentation is provided in HTML format; it is located at $QTDIR/doc/html and can be read using Qt Assistant or with a web browser. This man page is provided as a convenience for those users who prefer man pages, although this format is not officially supported by Trolltech. iykyk, man pages are a whole aesthetic π
If you find errors in 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 (3.3.8). include the receipts bestie, it helps so much π§
and that's the whole page, babes π this came to you from Trolltech AS, dated 2 February 2007, running Qt 3.3.8 β old, iconic, still out here serving TCP connections like it's nothing. go forth and newConnection() responsibly πΈβ¨π
π¦ where this page comes from
- fedora 43: qt3-devel-docs 3.3.8b-102.fc43 Β· QPL-1.0 OR GPL-2.0-only OR GPL-3.0-only
- fedora 44: qt3-devel-docs 3.3.8b-103.fc44 Β· QPL-1.0 OR GPL-2.0-only OR GPL-3.0-only
- Copyright 1992-2007 Trolltech ASA. All rights reserved. See the
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms