QAbstractSocket Class Reference |
Constant | Value | Description |
---|---|---|
QAbstractSocket::IPv4Protocol | 0 | IPv4 |
QAbstractSocket::IPv6Protocol | 1 | IPv6 |
QAbstractSocket::UnknownNetworkLayerProtocol | -1 | Other than IPv4 and IPv6 |
See also QSocketLayer::protocol().
This enum describes the socket errors that can occur.
Constant | Value | Description |
---|---|---|
QAbstractSocket::ConnectionRefusedError | 0 | The connection was refused by the peer (or timed out). |
QAbstractSocket::RemoteHostClosedError | 1 | The remote host closed the connection. |
QAbstractSocket::HostNotFoundError | 2 | The host address was not found. |
QAbstractSocket::SocketAccessError | 3 | The socket operation failed because the application lacked the required privileges. |
QAbstractSocket::SocketResourceError | 4 | The local system ran out of resources (e.g., too many sockets). |
QAbstractSocket::SocketTimeoutError | 5 | The socket operation timed out. |
QAbstractSocket::DatagramTooLargeError | 6 | The datagram was larger than the operating system's limit (which can be as low as 8192 bytes). |
QAbstractSocket::NetworkError | 7 | An error occurred with the network (e.g., the network cable was accidentally plugged out). |
QAbstractSocket::AddressInUseError | 8 | The address specified to QUdpSocket::bind() is already in use and was set to be exclusive. |
QAbstractSocket::SocketAddressNotAvailableError | 9 | The address specified to QUdpSocket::bind() does not belong to the host. |
QAbstractSocket::UnsupportedSocketOperationError | 10 | The requested socket operation is not supported by the local operating system (e.g., lack of IPv6 support). |
QAbstractSocket::UnknownSocketError | -1 | An unidentified error occurred. |
See also QAbstractSocket::error().
This enum describes the different states in which a socket can be.
Constant | Value | Description |
---|---|---|
QAbstractSocket::UnconnectedState | 0 | The socket is not connected. |
QAbstractSocket::HostLookupState | 1 | The socket is performing a host name lookup. |
QAbstractSocket::ConnectingState | 2 | The socket has started establishing a connection. |
QAbstractSocket::ConnectedState | 3 | A connection is established. |
QAbstractSocket::BoundState | 4 | The socket is bound to an address and port (for servers). |
QAbstractSocket::ClosingState | 6 | The socket is about to close (data may still be waiting to be written). |
QAbstractSocket::ListeningState | 5 | For internal use only. |
See also QAbstractSocket::state().
This enum describes the transport layer protocol.
Constant | Value | Description |
---|---|---|
QAbstractSocket::TcpSocket | 0 | TCP |
QAbstractSocket::UdpSocket | 1 | UDP |
QAbstractSocket::UnknownSocketType | -1 | Other than TCP and UDP |
See also QAbstractSocket::socketType().
Creates a new abstract socket of type socketType. The parent argument is passed to QObject's constructor.
See also socketType(), QTcpSocket, and QUdpSocket.
Destroys the socket.
Aborts the current connection and resets the socket. Unlike close(), this function immediately closes the socket, clearing any pending data in the write buffer.
See also close().
Returns the number of incoming bytes that are waiting to be read.
Reimplemented from QIODevice.
See also bytesToWrite() and read().
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.
Reimplemented from QIODevice.
See also bytesAvailable() and flush().
Returns true if a line of data can be read from the socket; otherwise returns false.
Reimplemented from QIODevice.
See also readLine().
Attempts to close the socket. If there is pending data waiting to be written, QAbstractSocket will enter ClosingState and wait until all data has been written. Eventually, it will enter UnconnectedState and emit the disconnected() signal.
Reimplemented from QIODevice.
See also abort().
Attempts to make a connection to hostName on the given port.
The socket is opened in the given openMode and first enters HostLookupState, then performs a host name lookup of hostName. If the lookup succeeds, hostFound() is emitted and QAbstractSocket enters ConnectingState. It then attempts to connect to the address or addresses returned by the lookup. Finally, if a connection is established, QAbstractSocket enters ConnectedState and emits connected().
At any point, the socket can emit error() to signal that an error occurred.
hostName may be an IP address in string form (e.g., "43.195.83.32"), or it may be a host name (e.g., "www.trolltech.com"). QAbstractSocket will do a lookup only if required. port is in native byte order.
See also state(), peerName(), peerAddress(), peerPort(), and waitForConnected().
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
Attempts to make a connection to address on port port.
This signal is emitted after connectToHost() has been called and a connection has been successfully established.
See also connectToHost() and connectionClosed().
Disconnects the socket's connection with the host.
See also connectToHost().
This signal is emitted when the socket has been disconnected.
See also connectToHost() and close().
Returns the type of error that last occurred.
See also state() and errorString().
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
This signal is emitted after an error occurred. The socketError parameter describes the type of error that occurred.
See also error() and errorString().
This function writes as much as possible from the internal write buffer to the underlying network socket, without blocking. If any data was written, this function returns true; otherwise false is returned.
Call this function if you need QAbstractSocket to start sending buffered data immediately. The number of bytes successfully written depends on the operating system. In most cases, you do not need to call this function, because QAbstractSocket will start sending data automatically once control goes back to the event loop. In the absence of an event loop, call waitForBytesWritten() instead.
See also write() and waitForBytesWritten().
This signal is emitted after connectToHost() has been called and the host lookup has succeeded.
See also connected().
Returns true if the socket is valid and ready for use; otherwise returns false.
See also state().
Returns the host address of the local socket if available; otherwise returns QHostAddress::Null.
This is normally the main IP address of the host, but can be QHostAddress::LocalHost (127.0.0.1) for connections to the local host.
See also localPort() and peerAddress().
Returns the host port number (in native byte order) of the local socket if available; otherwise returns 0.
See also localAddress() and peerPort().
Returns the address of the connected peer if the socket is in ConnectedState; otherwise returns QHostAddress::Null.
See also peerName(), peerPort(), and localAddress().
Returns the name of the peer as specified by connectToHost(), or an empty QString if connectToHost() has not been called.
See also peerAddress() and peerPort().
Returns the port of the connected peer if the socket is in ConnectedState; otherwise returns 0.
See also peerAddress() and localPort().
Returns the size of the internal read buffer. This limits the amount of data that the client can receive before you call read() or readAll().
A read buffer size of 0 (the default) means that the buffer has no size limit, ensuring that no data is lost.
See also setReadBufferSize() and read().
Sets the size of QAbstractSocket's internal read buffer to be size bytes.
If the buffer size is limited to a certain size, QAbstractSocket won't buffer more than this size of data. Exceptionally, a buffer size of 0 means that the read buffer is unlimited and all incoming data is buffered. This is the default.
This option is useful if you only read the data at certain points in time (e.g., in a real-time streaming application) or if you want to protect your socket against receiving too much data, which may eventually cause your application to run out of memory.
See also readBufferSize() and read().
Initializes QAbstractSocket with the native socket descriptor socketDescriptor. Returns true if socketDescriptor is accepted as a valid socket descriptor; otherwise returns false. The socket is opened in the mode specified by openMode, and enters the socket state specified by socketState.
See also socketDescriptor().
Sets the type of error that last occurred to socketError.
See also setSocketState() and setErrorString().
Sets the state of the socket to state.
See also state().
Returns the native socket descriptor of QAbstractSocket if this is available; otherwise returns -1.
The socket descriptor is not available when QAbstractSocket is in UnconnectedState.
See also setSocketDescriptor().
Returns the socket type (TCP, UDP, or other).
See also QTcpSocket and QUdpSocket.
Returns the state of the socket.
See also error().
This signal is emitted whenever QAbstractSocket's state changes. The socketState parameter is the new state.
See also state().
Waits until the socket is connected, up to msecs milliseconds. If the connection has been established, this function returns true; otherwise it returns false. In the case where it returns false, you can call error() to determine the cause of the error.
The following example waits up to one second for a connection to be established:
socket->connectToHost("imap", 143); if (socket->waitForConnected(1000)) qDebug("Connected!");
If msecs is -1, this function will not time out.
See also connectToHost() and connected().
Waits until the socket has disconnected, up to msecs milliseconds. If the connection has been disconnected, this function returns true; otherwise it returns false. In the case where it returns false, you can call error() to determine the cause of the error.
The following example waits up to one second for a connection to be closed:
socket->disconnect(); if (socket->waitForDisconnected(1000)) qDebug("Disconnected!");
If msecs is -1, this function will not time out.
See also disconnect() and close().
Cette page est une traduction d'une page de la documentation de Qt, écrite par Nokia Corporation and/or its subsidiary(-ies). Les éventuels problèmes résultant d'une mauvaise traduction ne sont pas imputables à Nokia. | Qt 4.0 | |
Copyright © 2012 Developpez LLC. Tous droits réservés Developpez LLC. Aucune reproduction, même partielle, ne peut être faite de ce site et de l'ensemble de son contenu : textes, documents et images sans l'autorisation expresse de Developpez LLC. Sinon, vous encourez selon la loi jusqu'à 3 ans de prison et jusqu'à 300 000 E de dommages et intérêts. Cette page est déposée à la SACD. | ||
Vous avez déniché une erreur ? Un bug ? Une redirection cassée ? Ou tout autre problème, quel qu'il soit ? Ou bien vous désirez participer à ce projet de traduction ? N'hésitez pas à nous contacter ou par MP ! |
Copyright © 2000-2012 - www.developpez.com