📄 qserversocket.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><!-- /home/reggie/tmp/qt-3.0-reggie-5401/qt-x11-commercial-3.0.5/src/network/qserversocket.cpp:53 --><html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>QServerSocket Class</title><style type="text/css"><!--h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm; }a:link { color: #004faf; text-decoration: none }a:visited { color: #672967; text-decoration: none }body { background: #ffffff; color: black; }--></style></head><body><table border="0" cellpadding="0" cellspacing="0" width="100%"><tr bgcolor="#E5E5E5"><td valign=center> <a href="index.html"><font color="#004faf">Home</font></a> | <a href="classes.html"><font color="#004faf">All Classes</font></a> | <a href="mainclasses.html"><font color="#004faf">Main Classes</font></a> | <a href="annotated.html"><font color="#004faf">Annotated</font></a> | <a href="groups.html"><font color="#004faf">Grouped Classes</font></a> | <a href="functions.html"><font color="#004faf">Functions</font></a></td><td align="right" valign="center"><img src="logo32.png" align="right" width="64" height="32" border="0"></td></tr></table><h1 align=center>QServerSocket Class Reference<br><small>[<a href="network.html">network module</a>]</small></h1><p>The QServerSocket class provides a TCP-based server.<a href="#details">More...</a><p><tt>#include <<a href="qserversocket-h.html">qserversocket.h</a>></tt><p>Inherits <a href="qobject.html">QObject</a>.<p><a href="qserversocket-members.html">List of all member functions.</a><h2>Public Members</h2><ul><li><div class=fn><a href="#QServerSocket"><b>QServerSocket</b></a> ( Q_UINT16 port, int backlog = 1, QObject * parent = 0, const char * name = 0 )</div></li><li><div class=fn><a href="#QServerSocket-2"><b>QServerSocket</b></a> ( const QHostAddress & address, Q_UINT16 port, int backlog = 1, QObject * parent = 0, const char * name = 0 )</div></li><li><div class=fn><a href="#QServerSocket-3"><b>QServerSocket</b></a> ( QObject * parent = 0, const char * name = 0 )</div></li><li><div class=fn>virtual <a href="#~QServerSocket"><b>~QServerSocket</b></a> ()</div></li><li><div class=fn>bool <a href="#ok"><b>ok</b></a> () const</div></li><li><div class=fn>Q_UINT16 <a href="#port"><b>port</b></a> () const</div></li><li><div class=fn>int <a href="#socket"><b>socket</b></a> () const</div></li><li><div class=fn>virtual void <a href="#setSocket"><b>setSocket</b></a> ( int socket )</div></li><li><div class=fn>QHostAddress <a href="#address"><b>address</b></a> () const</div></li><li><div class=fn>virtual void <a href="#newConnection"><b>newConnection</b></a> ( int socket ) = 0</div></li></ul><h2>Protected Members</h2><ul><li><div class=fn>QSocketDevice * <a href="#socketDevice"><b>socketDevice</b></a> ()</div></li></ul><hr><a name="details"></a><h2>Detailed Description</h2>The QServerSocket class provides a TCP-based server.<p> <p> <p> This class is a convenience class for accepting incoming TCPconnections. You can specify the port or have QServerSocket pick one,and listen on just one address or on all the machine's addresses.<p> Using the API is very simple: subclass QServerSocket, call theconstructor of your choice, and implement <a href="#newConnection">newConnection</a>() tohandle new incoming connections. There is nothing more to do.<p> (Note that due to lack of support in the underlying APIs,QServerSocket cannot accept or reject connections conditionally.)<p> <p>See also <a href="qsocket.html">QSocket</a>, <a href="qsocketdevice.html">QSocketDevice</a>, <a href="qhostaddress.html">QHostAddress</a>, <a href="qsocketnotifier.html">QSocketNotifier</a> and <a href="io.html">Input/Output and Networking</a>.<hr><h2>Member Function Documentation</h2><h3 class=fn><a name="QServerSocket"></a>QServerSocket::QServerSocket ( Q_UINT16 port, int backlog = 1, <a href="qobject.html">QObject</a> * parent = 0, const char * name = 0 )</h3>Creates a server socket object, that will serve the given <em>port</em> onall the addresses of this host. If <em>port</em> is 0, QServerSocket willpick a suitable port in a system-dependent manner. Use <em>backlog</em> tospecify how many pending connections the server can have.<p> The <em>parent</em> and <em>name</em> arguments are passed onto the <a href="qobject.html">QObject</a> constructor.<p> <b>Warning:</b> On Tru64 Unix systems a value of 0 for <em>backlog</em> means that youdon't accept any connections at all; you should specify a value larger than0.<h3 class=fn><a name="QServerSocket-2"></a>QServerSocket::QServerSocket ( const <a href="qhostaddress.html">QHostAddress</a> & address, Q_UINT16 port, int backlog = 1, <a href="qobject.html">QObject</a> * parent = 0, const char * name = 0 )</h3>Creates a server socket object, that will serve the given <em>port</em>only on the given <em>address</em>. Use <em>backlog</em> to specify how manypending connections the server can have.<p> The <em>parent</em> and <em>name</em> arguments are passed onto the <a href="qobject.html">QObject</a> constructor.<p> <b>Warning:</b> On Tru64 Unix systems a value of 0 for <em>backlog</em> means that youdon't accept any connections at all; you should specify a value larger than0.<h3 class=fn><a name="QServerSocket-3"></a>QServerSocket::QServerSocket ( <a href="qobject.html">QObject</a> * parent = 0, const char * name = 0 )</h3>Construct an empty server socket.<p> This constructor, in combination with <a href="#setSocket">setSocket</a>(), allows us to use theQServerSocket class as a wrapper for other socket types (e.g. Unix DomainSockets under Unix).<p> The <em>parent</em> and <em>name</em> arguments are passed onto the <a href="qobject.html">QObject</a> constructor.<p> <p>See also <a href="#setSocket">setSocket</a>().<h3 class=fn><a name="~QServerSocket"></a>QServerSocket::~QServerSocket ()<tt> [virtual]</tt></h3>Destroys the socket.<p> This causes any backlogged connections (connections thathave reached the host, but not yet been completely set up by calling<a href="qsocketdevice.html#accept">QSocketDevice::accept</a>()) to be severed.<p> Existing connections continue to exist; this only affects theacceptance of new connections.<h3 class=fn><a href="qhostaddress.html">QHostAddress</a> <a name="address"></a>QServerSocket::address () const</h3>Returns the address on which this object listens, or 0.0.0.0 ifthis object listens on more than one address. <a href="#ok">ok</a>() must be TRUE beforecalling this function.<p> <p>See also <a href="#port">port</a>() and <a href="qsocketdevice.html#address">QSocketDevice::address</a>().<h3 class=fn>void <a name="newConnection"></a>QServerSocket::newConnection ( int socket )<tt> [pure virtual]</tt></h3><p> This pure virtual function is responsible for setting up a newincoming connection. <em>socket</em> is the fd (file descripor) for thenewly accepted connection.<h3 class=fn>bool <a name="ok"></a>QServerSocket::ok () const</h3>Returns TRUE if the construction succeeded; otherwise returns FALSE.<h3 class=fn>Q_UINT16 <a name="port"></a>QServerSocket::port () const</h3>Returns the port number on which this server socket listens. Thisis always non-zero; if you specify 0 in the constructor,QServerSocket will pick a non-zero port itself. <a href="#ok">ok</a>() must be TRUEbefore calling this function.<p> <p>See also <a href="#address">address</a>() and <a href="qsocketdevice.html#port">QSocketDevice::port</a>().<p>Example: <a href="httpd-example.html#x638">network/httpd/httpd.cpp</a>.<h3 class=fn>void <a name="setSocket"></a>QServerSocket::setSocket ( int socket )<tt> [virtual]</tt></h3>Sets the socket to use <em>socket</em>. bind() and listen() should alreadyhave been called for <em>socket</em>.<p> This allows us to use the QServerSocket class as a wrapper for other sockettypes (e.g. Unix Domain Sockets under Unix).<h3 class=fn>int <a name="socket"></a>QServerSocket::socket () const</h3>Returns the operating system socket.<h3 class=fn><a href="qsocketdevice.html">QSocketDevice</a> * <a name="socketDevice"></a>QServerSocket::socketDevice ()<tt> [protected]</tt></h3>Returns a pointer to the internal socket device. The returned pointer isnull if there is no connection or pending connection.<p> There is normally no need to manipulate the socket device directly since thisclass does all the necessary setup for most client or server socketapplications.<!-- eof --><hr><p>This file is part of the <a href="index.html">Qt toolkit</a>.Copyright © 1995-2002<a href="http://www.trolltech.com/">Trolltech</a>. All Rights Reserved.<p><address><hr><div align=center><table width=100% cellspacing=0 border=0><tr><td>Copyright © 2002 <a href="http://www.trolltech.com">Trolltech</a><td><a href="http://www.trolltech.com/trademarks.html">Trademarks</a><td align=right><div align=right>Qt version 3.0.5</div></table></div></address></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -