QT QAbstractSocket类

来源:互联网 发布:php static class 编辑:程序博客网 时间:2024/05/16 04:34

QAbstractSocket is the base class for QTcpSocket and QUdpSocket and contains all common functionality of these two classes
是QTcpSocket and QUdpSocket的基类;

1.enum QAbstractSocket::SocketType:
QAbstractSocket::TcpSocket
QAbstractSocket::UdpSocket
QAbstractSocket::SctpSocket
QAbstractSocket::UnknownSocketType

2.void QAbstractSocket::abort()
立即断开当前套接字

3.bool QAbstractSocket::atEnd() const
Returns true if no more data is currently available for reading; otherwise returns false.
This function is most commonly used when reading data from the socket in a loop. For example:

 void SocketClass::readyReadSlot() {     while (!socket.atEnd()) {         QByteArray data = socket.read(100);         ....     } }

4.bool QAbstractSocket::bind(const QHostAddress &address, quint16 port = 0, BindMode mode = DefaultForPlatform)
5.bool QAbstractSocket::bind(quint16 port = 0, BindMode mode = DefaultForPlatform)

6.qint64 QAbstractSocket::bytesAvailable() const
Returns the number of incoming bytes that are waiting to be read.

7.qint64 QAbstractSocket::bytesToWrite() const
Returns the number of bytes that are waiting to be written. The bytes are written when control goes back to the event loop or when flush() is called.

8.bool QAbstractSocket::canReadLine() const
Returns true if a line of data can be read from the socket; otherwise returns false.

9.void QAbstractSocket::close()

9.void QAbstractSocket::connectToHost(const QString &hostName, quint16 port, OpenMode openMode = ReadWrite, NetworkLayerProtocol protocol = AnyIPProtocol)
(1)hostName may be an IP address in string form (e.g., “43.195.83.32”), or it may be a host name (e.g., “example.com”).

10.void QAbstractSocket::connectToHost(const QHostAddress &address, quint16 port, OpenMode openMode = ReadWrite)

11.void QAbstractSocket::connected() signal
This signal is emitted after connectToHost() has been called and a connection has been successfully established.

12.void QAbstractSocket::disconnected()
This signal is emitted when the socket has been disconnected.

13.void QAbstractSocket::disconnectFromHost()
Attempts to close the socket and wait until all data has been written.

14.bool QAbstractSocket::flush()

15.bool QAbstractSocket::isValid() const
Returns true if the socket is valid and ready for use; otherwise returns false.

16.QHostAddress QAbstractSocket::localAddress() const
Returns the host address of the local socket if available; otherwise returns QHostAddress::Null.
17.quint16 QAbstractSocket::localPort() const

18.SocketType QAbstractSocket::socketType() const
Returns the socket type (TCP, UDP, or other).

19.bool QAbstractSocket::waitForConnected(int msecs = 30000)
Waits until the socket is connected, up to msecs milliseconds. If the connection has been established, this function returns true; otherwise it returns false
20.bool QAbstractSocket::waitForDisconnected(int msecs = 30000)

原创粉丝点击