connectToHost() is the most-used function. As its name implies, it opens a connection to a named host.
.PP
Most network protocols are either packet-oriented or line-oriented. canReadLine() indicates whether a connection contains an entire unread line or not, and bytesAvailable() returns the number of bytes available for reading.
The signals error(), connected(), readyRead() and connectionClosed() inform you of the progress of the connection. There are also some less commonly used signals. hostFound() is emitted when connectToHost() has finished its DNS lookup and is starting its TCP connection. delayedCloseFinished() is emitted when close() succeeds. bytesWritten() is emitted when TQSocket moves data from its "to be written" queue into the TCP implementation.
There are several access functions for the socket: state() returns whether the object is idle, is doing a DNS lookup, is connecting, has an operational connection, etc. address() and port() return the IP address and port used for the connection. The peerAddress() and peerPort() functions return the IP address and port used by the peer, and peerName() returns the name of the peer (normally the name that was passed to connectToHost()). socketDevice() returns a pointer to the TQSocketDevice used for this socket.
TQSocket inherits TQIODevice, and reimplements some functions. In general, you can treat it as a TQIODevice for writing, and mostly also for reading. The match isn't perfect, since the TQIODevice API is designed for devices that are controlled by the same machine, and an asynchronous peer-to-peer network connection isn't quite like that. For example, there is nothing that matches TQIODevice::size() exactly. The documentation for open(), close(), flush(), size(), at(), atEnd(), readBlock(), writeBlock(), getch(), putch(), ungetch() and readLine() describes the differences in detail.
\fBWarning:\fR Because TQt doesn't use the native socketstream implementation on Mac OS X, TQSocket has an implicit transfer latency of 100ms. You can achieve lower latency on Mac OS X by using TQSocketDevice instead.
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
.PP
Moves the read index forward to \fIindex\fR and returns TRUE if the operation was successful; otherwise returns FALSE. Moving the index forward means skipping incoming data.
If the output buffer is empty, the state is set to TQSocket::Idle and the connection is terminated immediately. If the output buffer still contains data to be written, TQSocket goes into the TQSocket::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 TQSocket::Idle and the connection is terminated. At this point, the delayedCloseFinished() signal is emitted.
Any connection or pending connection is closed immediately, and TQSocket 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().
\fIhost\fR may be an IP address in string form, or it may be a DNS name. TQSocket will do a normal DNS lookup if required. Note that \fIport\fR is in native byte order, unlike some other libraries.
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.
.PP
See also connectToHost() and close().
.PP
Examples:
.)l network/clientserver/client/client.cpp, network/clientserver/server/server.cpp, and network/networkprotocol/nntp.cpp.
If you call close() and there is buffered output data to be written, TQSocket goes into the TQSocket::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.
Opens the socket using the specified TQIODevice file mode \fIm\fR. This function is called automatically when needed and you should not call it yourself.
This signal is emitted every time there is new incoming data.
.PP
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.
.PP
See also readBlock(), readLine(), and bytesAvailable().
.PP
Examples:
.)l network/clientserver/client/client.cpp, network/httpd/httpd.cpp, network/mail/smtp.cpp, and network/networkprotocol/nntp.cpp.
Usually TQSocket 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 TQSocket 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.
.PP
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.
Sets the internal socket device to \fIdevice\fR. Passing a \fIdevice\fR of 0 will cause the internal socket device to be used. Any existing connection will be disconnected before using the new \fIdevice\fR.
This implementation of the virtual function TQIODevice::ungetch() prepends the character \fIch\fR to the read buffer so that the next read returns this character as the first character of the output.
Wait up to \fImsecs\fR milliseconds for more data to be available.
.PP
If \fImsecs\fR is -1 the call will block indefinitely.
.PP
Returns the number of bytes available.
.PP
If \fItimeout\fR is non-null and no error occurred (i.e. it does not return -1): this function sets \fI*timeout\fR to TRUE, if the reason for returning was that the timeout was reached; otherwise it sets \fI*timeout\fR to FALSE. This is useful to find out if the peer closed the connection.
.PP
\fBWarning:\fR This is a blocking call and should be avoided in event driven applications.