Q3Socket Class Reference
|
Constant | Value | Description |
---|---|---|
Q3Socket::ErrConnectionRefused | 0 | if the connection was refused |
Q3Socket::ErrHostNotFound | 1 | if the host was not found |
Q3Socket::ErrSocketRead | 2 | if a read from the socket failed |
This enum defines the connection states:
Constant | Value | Description |
---|---|---|
Q3Socket::Idle | 0 | if there is no connection |
Q3Socket::HostLookup | 1 | during a DNS lookup |
Q3Socket::Connecting | 2 | during TCP connection establishment |
Q3Socket::Connected | 3 | when there is an operational connection |
Q3Socket::Closing | 4 | if the socket is closing down, but is not yet closed. |
Creates a Q3Socket object in Q3Socket::Idle state.
The parent and name arguments are passed on to the QObject constructor.
Destroys the socket. Closes the connection if necessary.
See also close().
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.)
Returns the current read index. Since Q3Socket is a sequential device, the current read index is always zero.
This is an overloaded member function, provided for convenience.
Moves the read index forward to index and returns true if the operation was successful; otherwise returns false. Moving the index forward means skipping incoming data.
Returns true if there is no more data to read; otherwise returns false.
Reimplemented from QIODevice.
Returns the number of incoming bytes that can be read, i.e. the size of the input buffer. Equivalent to size().
Reimplemented from QIODevice.
See also bytesToWrite().
Returns the number of bytes that are waiting to be written, i.e. the size of the output buffer.
Reimplemented from QIODevice.
See also bytesAvailable() and clearPendingData().
This signal is emitted when data has been written to the network. The nbytes parameter specifies how many bytes were written.
The bytesToWrite() function is often used in the same context; it indicates how many buffered bytes there are left to write.
See also writeBlock() and bytesToWrite().
Returns true if it's possible to read an entire line of text from this socket at this time; otherwise returns false.
Note that if the peer closes the connection unexpectedly, this function returns false. This means that loops such as this won't work:
while( !socket->canReadLine() ) // WRONG
;
Reimplemented from QIODevice.
See also readLine().
Deletes the data that is waiting to be written. This is useful if you want to close the socket without waiting for all the data to be written.
See also bytesToWrite(), close(), and delayedCloseFinished().
Closes the socket.
The read buffer is cleared.
If the output buffer is empty, the state is set to Q3Socket::Idle and the connection is terminated immediately. If the output buffer still contains data to be written, Q3Socket goes into the Q3Socket::Closing state and the rest of the data will be written. When all of the outgoing data have been written, the state is set to Q3Socket::Idle and the connection is terminated. At this point, the delayedCloseFinished() signal is emitted.
If you don't want that the data of the output buffer is written, call clearPendingData() before you call close().
Reimplemented from QIODevice.
See also state(), bytesToWrite(), and clearPendingData().
Attempts to make a connection to host on the specified port and return immediately.
Any connection or pending connection is closed immediately, and Q3Socket goes into the HostLookup state. When the lookup succeeds, it emits hostFound(), starts a TCP connection and goes into the Connecting state. Finally, when the connection succeeds, it emits connected() and goes into the Connected state. If there is an error at any point, it emits error().
host may be an IP address in string form, or it may be a DNS name. Q3Socket will do a normal DNS lookup if required. Note that port is in native byte order, unlike some other libraries.
See also state().
This signal is emitted after connectToHost() has been called and a connection has been successfully established.
See also connectToHost() and connectionClosed().
This signal is emitted when the other end has closed the connection. The read buffers may contain buffered input data which you can read after the connection was closed.
See also connectToHost() and close().
This signal is emitted when a delayed close is finished.
If you call close() and there is buffered output data to be written, Q3Socket goes into the Q3Socket::Closing state and returns immediately. It will then keep writing to the socket until all the data has been written. Then, the delayedCloseFinished() signal is emitted.
See also close().
This signal is emitted after an error occurred. The error parameter is the Error value.
Implementation of the abstract virtual QIODevice::flush() function. This function always returns true.
Reads a single byte/character from the internal read buffer. Returns the byte/character read, or -1 if there is nothing to be read.
See also bytesAvailable() and putch().
This signal is emitted after connectToHost() has been called and the host lookup has succeeded.
See also connected().
Opens the socket using the specified QIODevice file mode m. This function is called automatically when needed and you should not call it yourself.
Reimplemented from QIODevice.
See also close().
This is an overloaded member function, provided for convenience.
Returns the address of the connected peer if the socket is in Connected state; otherwise an empty QHostAddress is returned.
Returns the host name as specified to the connectToHost() function. An empty string is returned if none has been set.
Returns the peer's host port number, normally as specified to the connectToHost() function. If none has been set, this function returns 0.
Note that Qt always uses native byte order, i.e. 67 is 67 in Qt; there is no need to call htons().
Returns the host port number of this socket, in native byte order.
Writes the character ch to the output buffer.
Returns ch, or -1 if an error occurred.
See also getch().
Returns the size of the read buffer.
See also setReadBufferSize().
Reads maxlen bytes from the socket into data and returns the number of bytes read. Returns -1 if an error occurred.
Reimplemented from QIODevice.
This signal is emitted every time there is new incoming data.
Bear in mind that new incoming data is only reported once; if you do not read all the data, this class buffers the data and you can read it later, but no signal is emitted unless new data arrives. A good practice is to read all data in the slot connected to this signal unless you are sure that you need to receive more data to be able to process it.
See also readBlock(), readLine(), and bytesAvailable().
Sets the size of the Q3Socket's internal read buffer to bufSize.
Usually Q3Socket reads all data that is available from the operating system's socket. If the buffer size is limited to a certain size, this means that the Q3Socket class doesn't buffer more than this size of data.
If the size of the read buffer is 0, the read buffer is unlimited and all incoming data is buffered. This is the default.
If you read the data in the readyRead() signal, you shouldn't use this option since it might slow down your program unnecessary. This option is useful if you only need to read the data at certain points in time, like in a realtime streaming application.
See also readBufferSize().
Sets the socket to use socket and the state() to Connected. The socket must already be connected.
This allows us to use the Q3Socket class as a wrapper for other socket types (e.g. Unix Domain Sockets).
See also socket().
Sets the internal socket device to device. Passing a device of 0 will cause the internal socket device to be used. Any existing connection will be disconnected before using the new device.
The new device should not be connected before being associated with a Q3Socket; after setting the socket call connectToHost() to make the connection.
This function is useful if you need to subclass Q3SocketDevice and want to use the Q3Socket API, for example, to implement Unix domain sockets.
See also socketDevice().
Returns the number of incoming bytes that can be read right now (like bytesAvailable()).
Reimplemented from QIODevice.
Returns the socket number, or -1 if there is no socket at the moment.
See also setSocket().
Returns a pointer to the internal socket device.
There is normally no need to manipulate the socket device directly since this class does the necessary setup for most applications.
See also setSocketDevice().
Returns the current state of the socket connection.
See also Q3Socket::State.
This implementation of the virtual function QIODevice::ungetch() prepends the character ch to the read buffer so that the next read returns this character as the first character of the output.
Wait up to msecs milliseconds for more data to be available.
If msecs is -1 the call will block indefinitely.
Returns the number of bytes available.
If timeout is non-null and no error occurred (i.e. it does not return -1): this function sets *timeout to true, if the reason for returning was that the timeout was reached; otherwise it sets *timeout to false. This is useful to find out if the peer closed the connection.
Warning: This is a blocking call and should be avoided in event driven applications.
See also bytesAvailable().
This is an overloaded member function, provided for convenience.
Writes len bytes to the socket from data and returns the number of bytes written. Returns -1 if an error occurred.
Reimplemented from QIODevice.
Copyright © 2008 Nokia | Trademarks | Qt 4.4.3 |
Попытка перевода Qt документации. Если есть желание присоединиться, или если есть замечания или пожелания, то заходите на форум: Перевод Qt документации на русский язык... Люди внесшие вклад в перевод: Команда переводчиков |