The QSocket class provides a buffered socket connection. More...
#include <qsocket.h>
Inherits QIODevice and QObject.
This class provides a buffered TCP connection over a socket. Both read and write operations are buffered.
See also: QSocketDevice, QSocketAddress and QSocketNotifier.
QSocket::Binary
(default)
QSocket::Ascii
QSocket::Idle
if there is no connection,
QSocket::HostLookup
during a host lookup,
QSocket::Connecting
during an attempt to connect to a host, and
QSocket::Connection
when there is a connection.
Creates a QSocket object in QSocket::Idle
state.
This socket can be used to make a connection to a host using the connectToHost() function.
Creates a QSocket object for an existing connection using socket.
The socket is set to nonblocking and the socket option QSocketDevice::ReuseAddress
is enabled.
Destroys the socket. Closes the connection if necessary.
See also: close().
[virtual]
Moves the read index forward and returns TRUE if the operation was successful. Moving the index forward means skipping incoming data.
Reimplemented from QIODevice.
[virtual]
Returns the current read index. Since QSocket is a sequential device, the current read index is always zero.
Reimplemented from QIODevice.
[virtual]
Returns TRUE if there is no more data to read, otherwise 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().
See also: bytesToWrite();.
Returns the number of bytes that are waiting to be written, i.e. the size of the output buffer.
See also: bytesAvailable.
[signal]
This signal is emitted when data actually has been written to the network. The nbytes parameter says how many bytes were written.
The bytesToWrite() function is often used in the same context, and it tells how many buffered bytes there are left to write.
See also: writeBlock() and bytesToWrite().
Returns TRUE if the socket is in ascii mode and readLine() can be called to read a line of text. Otherwise FALSE is returned.
See also: setMode() and readLine().
[virtual]
Closes the socket.
The mode to QSocket::Binary
and the read buffer is cleared.
If the output buffer is empty, the state is set to \ QSocket::Idle
and the connection is terminated immediately. If the output buffer
still contains data to be written, QSocket goes into the
QSocket::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 QSocket::Idle
and the connection is terminated. At this
point, the delayedCloseFinished() signal is emitted.
See also: state(), setMode() and bytesToWrite().
Reimplemented from QIODevice.
[signal]
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().
Attempts to make a connection to host on the specified port.
Any connection or pending connection is closed immediately when you call this function.
When making a connection, QSocket goes into the QSocket::HostLookup
state while looking up the host. When the host has been found, QSocket
will try to connect to the host and it goes into the
QSocket::Connecting
state. Finally, when a connection has been
made, the state becomes QSocket::Connection.
TODO### No real error handling so far. Blocking host lookup.
See also: state().
[signal]
This signal is emitted after connectToHost() has been called and a connection has been successfully established.
See also: connectToHost() and closed().
[signal]
This signal is emitted when a delayed close is finished. If you call
close() and there is buffered output data to be written, QSocket goes
into the QSocket::Closing
state and returns immediately. It will
then keep writing to the socket until all the data has been written.
Then, the delayCloseFinished() signal is emitted.
See also: close().
[virtual]
Implementation of the abstract virtual QIODevice::flush() function. This implementation is a no-op.
Reimplemented from QIODevice.
[virtual]
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().
Reimplemented from QIODevice.
Returns the host name as specified to the connectToHost() function. If none has been set, the returned host name is "".
[signal]
This signal is emitted after connectToHost() has been called and a host has been looked up.
See also: connected().
Returns the current communication mode, either QSocket::Binary
or QSocket::Ascii.
The default mode is QSocket::Binary.
The documentation of setMode() explains this mode setting.
See also: setMode().
[virtual]
Opens the socket using the specified QIODevice file mode. This function is called automatically when needed and you should not call it yourself.
See also: close().
Reimplemented from QIODevice.
Returns the host port as specified to the connectToHost() function. If none has been set, the returned port is 0.
[virtual]
Writes the character ch into the output buffer.
Returns ch, or -1 if some error occurred.
See also: getch().
Reimplemented from QIODevice.
[virtual]
Reads max maxlen bytes from the socket into data and returns the number of bytes read. Returns -1 if an error occurred.
Reimplemented from QIODevice.
Returns a line of text including a terminating newline character (\n). Returns "" if canReadLine() returns FALSE.
See also: canReadLine().
[signal]
This signal is emitted when there is incoming data to be read.
When new data comes into the socket device, this signal is emitted immediately. If QSocket has old incoming data that you have not read, the signal is emitted once every second until you read everything.
See also: readBlock(), readLine() and bytesAvailable().
Sets the communication mode to either binary or ascii.
QSocket::Binary is the default.
The mode only relates to incoming data. If binary mode is set, you read data using the readBlock() function. bytesAvailable() tells you how much buffered data that can be read.
If ascii mode set, QSocket will look for newline characters (\n) in the incoming data. You can call the canReadLine() function to check if there is a line of text to be read. If canReadLine() returns TRUE, you can read a complete line of incoming text using the readLine() function. The readBlock() and bytesAvailable() functions work just like in binary mode.
The close() function sets the mode to QSocket::Binary.
See also: mode(), readBlock(), bytesAvailable(), canReadLine(), readLine() and close().
[virtual]
Returns the number of incoming bytes that can be read, same as bytesAvailable().
Reimplemented from QIODevice.
[virtual protected slot]
Internal slot for handling socket read notifications.
[virtual protected slot]
Internal slot for handling socket write notifications.
[protected]
Returns a pointer to the internal socket device. The returned pointer is null if there is no connection or pending connection.
There is normally no need to manipulate the socket device directly since this class does all the necessary setup for most client or server socket applications.
Returns the current state of the socket connection.
[virtual protected]
Processes timer events for QSocket. Emits the readyRead() signal if there if there is buffered input available for reading.
Reimplemented from QObject.
[virtual]
This implementation of the virtual function QIODevice::ungetch() always returns -1 (error) because a QSocket is a sequential device and does not allow any ungetch operation.
Reimplemented from QIODevice.
[virtual]
Writes len bytes from the socket from data and returns the number of bytes written. Returns -1 if an error occurred.
Reimplemented from QIODevice.
Search the documentation, FAQ, qt-interest archive and more (uses
www.troll.no):
This file is part of the Qt toolkit, copyright © 1995-99 Troll Tech, all rights reserved.
Copyright © 1999 Troll Tech | Trademarks | Qt version 2.0.2
|