![]() |
Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
|
The QTcpSocket class provides a TCP socket. More...
#include <qtcpsocket.h>
Public Member Functions | |
QTcpSocket (QObject *parent=nullptr) | |
Creates a QTcpSocket object in state UnconnectedState . | |
virtual | ~QTcpSocket () |
Destroys the socket, closing the connection if necessary. | |
Public Member Functions inherited from QAbstractSocket | |
QAbstractSocket (SocketType socketType, QObject *parent) | |
Creates a new abstract socket of type socketType. | |
virtual | ~QAbstractSocket () |
Destroys the socket. | |
virtual void | resume () |
PauseModes | pauseMode () const |
void | setPauseMode (PauseModes pauseMode) |
virtual bool | bind (const QHostAddress &address, quint16 port=0, BindMode mode=DefaultForPlatform) |
bool | bind (QHostAddress::SpecialAddress addr, quint16 port=0, BindMode mode=DefaultForPlatform) |
bool | bind (quint16 port=0, BindMode mode=DefaultForPlatform) |
virtual void | connectToHost (const QString &hostName, quint16 port, OpenMode mode=ReadWrite, NetworkLayerProtocol protocol=AnyIPProtocol) |
Attempts to make a connection to hostName on the given port. | |
void | connectToHost (const QHostAddress &address, quint16 port, OpenMode mode=ReadWrite) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Attempts to make a connection to address on port port. | |
virtual void | disconnectFromHost () |
Attempts to close the socket. | |
bool | isValid () const |
Returns true if the socket is valid and ready for use; otherwise returns false . | |
qint64 | bytesAvailable () const override |
Returns the number of incoming bytes that are waiting to be read. | |
qint64 | bytesToWrite () const override |
Returns the number of bytes that are waiting to be written. | |
quint16 | localPort () const |
Returns the host port number (in native byte order) of the local socket if available; otherwise returns 0. | |
QHostAddress | localAddress () const |
Returns the host address of the local socket if available; otherwise returns QHostAddress::Null. | |
quint16 | peerPort () const |
Returns the port of the connected peer if the socket is in ConnectedState; otherwise returns 0. | |
QHostAddress | peerAddress () const |
Returns the address of the connected peer if the socket is in ConnectedState; otherwise returns QHostAddress::Null. | |
QString | peerName () const |
Returns the name of the peer as specified by connectToHost(), or an empty QString if connectToHost() has not been called. | |
qint64 | readBufferSize () const |
Returns the size of the internal read buffer. | |
virtual void | setReadBufferSize (qint64 size) |
Sets the size of QAbstractSocket's internal read buffer to be size bytes. | |
void | abort () |
Aborts the current connection and resets the socket. | |
virtual qintptr | socketDescriptor () const |
Returns the native socket descriptor of the QAbstractSocket object if this is available; otherwise returns -1. | |
virtual bool | setSocketDescriptor (qintptr socketDescriptor, SocketState state=ConnectedState, OpenMode openMode=ReadWrite) |
Initializes QAbstractSocket with the native socket descriptor socketDescriptor. | |
virtual void | setSocketOption (QAbstractSocket::SocketOption option, const QVariant &value) |
virtual QVariant | socketOption (QAbstractSocket::SocketOption option) |
SocketType | socketType () const |
Returns the socket type (TCP, UDP, or other). | |
SocketState | state () const |
Returns the state of the socket. | |
SocketError | error () const |
Returns the type of error that last occurred. | |
void | close () override |
Closes the I/O device for the socket and calls disconnectFromHost() to close the socket's connection. | |
bool | isSequential () const override |
\reimp | |
bool | flush () |
This function writes as much as possible from the internal write buffer to the underlying network socket, without blocking. | |
virtual bool | waitForConnected (int msecs=30000) |
Waits until the socket is connected, up to msecs milliseconds. | |
bool | waitForReadyRead (int msecs=30000) override |
This function blocks until new data is available for reading and the \l{QIODevice::}{readyRead()} signal has been emitted. | |
bool | waitForBytesWritten (int msecs=30000) override |
\reimp | |
virtual bool | waitForDisconnected (int msecs=30000) |
Waits until the socket has disconnected, up to msecs milliseconds. | |
void | setProxy (const QNetworkProxy &networkProxy) |
QNetworkProxy | proxy () const |
QString | protocolTag () const |
void | setProtocolTag (const QString &tag) |
Protected Member Functions | |
QTcpSocket (QTcpSocketPrivate &dd, QObject *parent=nullptr) | |
QTcpSocket (QAbstractSocket::SocketType socketType, QTcpSocketPrivate &dd, QObject *parent=nullptr) | |
Protected Member Functions inherited from QAbstractSocket | |
qint64 | readData (char *data, qint64 maxlen) override |
\reimp | |
qint64 | readLineData (char *data, qint64 maxlen) override |
\reimp | |
qint64 | skipData (qint64 maxSize) override |
\reimp | |
qint64 | writeData (const char *data, qint64 len) override |
\reimp | |
void | setSocketState (SocketState state) |
Sets the state of the socket to state. | |
void | setSocketError (SocketError socketError) |
Sets the type of error that last occurred to socketError. | |
void | setLocalPort (quint16 port) |
void | setLocalAddress (const QHostAddress &address) |
void | setPeerPort (quint16 port) |
void | setPeerAddress (const QHostAddress &address) |
void | setPeerName (const QString &name) |
QAbstractSocket (SocketType socketType, QAbstractSocketPrivate &dd, QObject *parent=nullptr) |
The QTcpSocket class provides a TCP socket.
\reentrant
\inmodule QtNetwork
TCP (Transmission Control Protocol) is a reliable, stream-oriented, connection-oriented transport protocol. It is especially well suited for continuous transmission of data.
QTcpSocket is a convenience subclass of QAbstractSocket that allows you to establish a TCP connection and transfer streams of data. See the QAbstractSocket documentation for details.
Definition at line 18 of file qtcpsocket.h.
|
explicit |
Creates a QTcpSocket object in state UnconnectedState
.
parent is passed on to the QObject constructor.
Definition at line 46 of file qtcpsocket.cpp.
|
virtual |
Destroys the socket, closing the connection if necessary.
Definition at line 61 of file qtcpsocket.cpp.
|
protected |
Definition at line 71 of file qtcpsocket.cpp.
|
protected |
Definition at line 80 of file qtcpsocket.cpp.