📄 qsocket.3qt
字号:
'\" t.TH QSocket 3qt "9 December 2002" "Trolltech AS" \" -*- nroff -*-.\" Copyright 1992-2001 Trolltech AS. All rights reserved. See the.\" license file included in the distribution for a complete license.\" statement..\".ad l.nh.SH NAMEQSocket \- Buffered TCP connection.SH SYNOPSIS\fC#include <qsocket.h>\fR.PPInherits QObject and QIODevice..PP.SS "Public Members".in +1c.ti -1c.BI "enum \fBError\fR { ErrConnectionRefused, ErrHostNotFound, ErrSocketRead }".br.ti -1c.BI "\fBQSocket\fR ( QObject * parent = 0, const char * name = 0 )".br.ti -1c.BI "virtual \fB~QSocket\fR ()".br.ti -1c.BI "enum \fBState\fR { Idle, HostLookup, Connecting, Connected, Closing, Connection = Connected }".br.ti -1c.BI "State \fBstate\fR () const".br.ti -1c.BI "int \fBsocket\fR () const".br.ti -1c.BI "virtual void \fBsetSocket\fR ( int socket )".br.ti -1c.BI "QSocketDevice * \fBsocketDevice\fR ()".br.ti -1c.BI "virtual void \fBsetSocketDevice\fR ( QSocketDevice * device )".br.ti -1c.BI "virtual void \fBconnectToHost\fR ( const QString & host, Q_UINT16 port )".br.ti -1c.BI "QString \fBpeerName\fR () const".br.ti -1c.BI "virtual bool \fBopen\fR ( int m )".br.ti -1c.BI "virtual void \fBclose\fR ()".br.ti -1c.BI "virtual void \fBflush\fR ()".br.ti -1c.BI "virtual Offset \fBsize\fR () const".br.ti -1c.BI "virtual Offset \fBat\fR () const".br.ti -1c.BI "virtual bool \fBat\fR ( Offset index )".br.ti -1c.BI "virtual bool \fBatEnd\fR () const".br.ti -1c.BI "Q_ULONG \fBbytesAvailable\fR () const".br.ti -1c.BI "Q_ULONG \fBwaitForMore\fR ( int msecs, bool * timeout ) const".br.ti -1c.BI "Q_ULONG \fBwaitForMore\fR ( int msecs ) const".br.ti -1c.BI "Q_ULONG \fBbytesToWrite\fR () const".br.ti -1c.BI "void \fBclearPendingData\fR ()".br.ti -1c.BI "virtual Q_LONG \fBreadBlock\fR ( char * data, Q_ULONG maxlen )".br.ti -1c.BI "virtual Q_LONG \fBwriteBlock\fR ( const char * data, Q_ULONG len )".br.ti -1c.BI "virtual int \fBgetch\fR ()".br.ti -1c.BI "virtual int \fBputch\fR ( int ch )".br.ti -1c.BI "virtual int \fBungetch\fR ( int ch )".br.ti -1c.BI "bool \fBcanReadLine\fR () const".br.ti -1c.BI "virtual QString \fBreadLine\fR ()".br.ti -1c.BI "Q_UINT16 \fBport\fR () const".br.ti -1c.BI "Q_UINT16 \fBpeerPort\fR () const".br.ti -1c.BI "QHostAddress \fBaddress\fR () const".br.ti -1c.BI "QHostAddress \fBpeerAddress\fR () const".br.in -1c.SS "Signals".in +1c.ti -1c.BI "void \fBhostFound\fR ()".br.ti -1c.BI "void \fBconnected\fR ()".br.ti -1c.BI "void \fBconnectionClosed\fR ()".br.ti -1c.BI "void \fBdelayedCloseFinished\fR ()".br.ti -1c.BI "void \fBreadyRead\fR ()".br.ti -1c.BI "void \fBbytesWritten\fR ( int nbytes )".br.ti -1c.BI "void \fBerror\fR ( int )".br.in -1c.SH DESCRIPTIONThe QSocket class provides a buffered TCP connection..PPIt provides a totally non-blocking QIODevice, and modifies and extends the API of QIODevice with socket-specific code..PPThe functions you're likely to call most are connectToHost(), bytesAvailable(), canReadLine() and the ones it inherits from QIODevice..PPconnectToHost() is the most-used function. As its name implies, it opens a connection to a named host..PPMost network protocols are either packet-oriented or line-oriented. canReadLine() indicates whether a connection contains an entire unread line or not, and bytesAvailable() returns the number of bytes available for reading..PPThe signals error(), connected(), readyRead() and connectionClosed() inform you of the progress of the connection. There are also some less commonly used signals. hostFound() is emitted when connectToHost() has finished its DNS lookup and is starting its TCP connection. delayedCloseFinished() is emitted when close() succeeds. bytesWritten() is emitted when QSocket moves data from its "to be written" queue into the TCP implementation..PPThere are several access functions for the socket: state() returns whether the object is idle, is doing a DNS lookup, is connecting, has an operational connection, etc. address() and port() return the IP address and port used for the connection. The peerAddress() and peerPort() functions return the IP address and port used by the peer, and peerName() returns the name of the peer (normally the name that was passed to connectToHost()). socket() returns a pointer to the QSocketDevice used for this socket..PPQSocket inherits QIODevice, and reimplements some functions. In general, you can treat it as a QIODevice for writing, and mostly also for reading. The match isn't perfect, since the QIODevice API is designed for devices that are controlled by the same machine, and an asynchronous peer-to-peer network connection isn't quite like that. For example, there is nothing that matches QIODevice::size() exactly. The documentation for open(), close(), flush(), size(), at(), atEnd(), readBlock(), writeBlock(), getch(), putch(), ungetch() and readLine() describes the differences in detail..PPSee also QSocketDevice, QHostAddress, QSocketNotifier, and Input/Output and Networking..SS "Member Type Documentation".SH "QSocket::Error"This enum specifies the possible errors:.TP\fCQSocket::ErrConnectionRefused\fR - if the connection was refused.TP\fCQSocket::ErrHostNotFound\fR - if the host was not found.TP\fCQSocket::ErrSocketRead\fR - if a read from the socket failed.SH "QSocket::State"This enum defines the connection states:.TP\fCQSocket::Idle\fR - if there is no connection.TP\fCQSocket::HostLookup\fR - during a DNS lookup.TP\fCQSocket::Connecting\fR - during TCP connection establishment.TP\fCQSocket::Connected\fR - when there is an operational connection.TP\fCQSocket::Closing\fR - if the socket is closing down, but is not yet closed..SH MEMBER FUNCTION DOCUMENTATION.SH "QSocket::QSocket ( QObject * parent = 0, const char * name = 0 )"Creates a QSocket object in QSocket::Idle state..PPThe \fIparent\fR and \fIname\fR arguments are passed on to the QObject constructor..SH "QSocket::~QSocket ()\fC [virtual]\fR"Destroys the socket. Closes the connection if necessary..PPSee also close()..SH "QHostAddress QSocket::address () const"Returns the host address of this socket. (This is normally the main IP address of the host, but can be e.g. 127.0.0.1 for connections to localhost.).SH "Offset QSocket::at () const\fC [virtual]\fR"Returns the current read index. Since QSocket is a sequential device, the current read index is always zero..PPReimplemented from QIODevice..SH "bool QSocket::at ( Offset index )\fC [virtual]\fR"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..PPMoves the read index forward to \fIindex\fR and returns TRUE if the operation was successful; otherwise returns FALSE. Moving the index forward means skipping incoming data..PPReimplemented from QIODevice..SH "bool QSocket::atEnd () const\fC [virtual]\fR"Returns TRUE if there is no more data to read; otherwise returns FALSE..PPReimplemented from QIODevice..SH "Q_ULONG QSocket::bytesAvailable () const"Returns the number of incoming bytes that can be read, i.e. the size of the input buffer. Equivalent to size()..PPSee also bytesToWrite()..PPExample: network/networkprotocol/nntp.cpp..SH "Q_ULONG QSocket::bytesToWrite () const"Returns the number of bytes that are waiting to be written, i.e. the size of the output buffer..PPSee also bytesAvailable() and clearPendingData()..SH "void QSocket::bytesWritten ( int nbytes )\fC [signal]\fR"This signal is emitted when data has been written to the network. The \fInbytes\fR parameter specifies how many bytes were written..PP
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -