This class provides a low level API for working with sockets. Users of this class are assumed to have networking experience. For most users the TQSocket class provides a much easier and high level alternative, but certain things (like UDP) can't be done with TQSocket and if you need a platform-independent API for those, TQSocketDevice is the right choice.
When calling connect() or bind(), TQSocketDevice detects the protocol family (IPv4, IPv6) automatically. Passing the protocol family to TQSocketDevice's constructor or to setSocket() forces creation of a socket device of a specific protocol. If not set, the protocol will be detected at the first call to connect() or bind().
\fCTQSocketDevice::Unknown\fR - The protocol family of the socket is not known. This can happen if you use TQSocketDevice with an already existing socket; it tries to determine the protocol family, but this can fail if the protocol family is not known to TQSocketDevice.
The \fItype\fR argument must be either TQSocketDevice::Stream for a reliable, connection-oriented TCP socket, or TQSocketDevice::Datagram for an unreliable UDP socket.
The \fItype\fR argument must be either TQSocketDevice::Stream for a reliable, connection-oriented TCP socket, or TQSocketDevice::Datagram for an unreliable UDP socket.
The \fIprotocol\fR indicates whether the socket should be of type IPv4 or IPv6. Passing Unknown is not meaningful in this context and you should avoid using (it creates an IPv4 socket, but your code is not easily readable).
.PP
The argument \fIdummy\fR is necessary for compatibility with some compilers.
The \fItype\fR argument must match the actual socket type; use TQSocketDevice::Stream for a reliable, connection-oriented TCP socket, or TQSocketDevice::Datagram for an unreliable, connectionless UDP socket.
Extracts the first connection from the queue of pending connections for this socket and returns a new socket identifier. Returns -1 if the operation failed.
Assigns a name to an unnamed socket. The name is the host address \fIaddress\fR and the port number \fIport\fR. If the operation succeeds, bind() returns TRUE; otherwise it returns FALSE without changing what port() and address() return.
.PP
bind() is used by servers for setting up incoming connections. Call bind() before listen().
\fBWarning:\fR On Microsoft Windows, we use the ioctlsocket() function to determine the number of bytes queued on the socket. According to Microsoft (KB Q125486), ioctlsocket() sometimes returns an incorrect number. The only safe way to determine the amount of data on the socket is to read it using readBlock(). TQSocket has workarounds to deal with this problem.
Connects to the IP address and port specified by \fIaddr\fR and \fIport\fR. Returns TRUE if it establishes a connection; otherwise returns FALSE. If it returns FALSE, error() explains why.
.PP
Note that error() commonly returns NoError for non-blocking sockets; this just means that you can call connect() again in a little while and it'll probably succeed.
Specifies how many pending connections a server socket can have. Returns TRUE if the operation was successful; otherwise returns FALSE. A \fIbacklog\fR value of 50 is quite common.
The listen() call only applies to sockets where type() is Stream, i.e. not to Datagram sockets. listen() must not be called before bind() or after accept().
Returns the address of the port this socket device is connected to. This may be 0.0.0.0 for a while, but is set to something sensible as soon as a sensible value is available.
.PP
Note that for Datagram sockets, this is the source port of the last packet received.
Returns the port number of the port this socket device is connected to. This may be 0 for a while, but is set to something sensible as soon as a sensible value is available.
.PP
Note that for Datagram sockets, this is the source port of the last packet received, and that it is in native byte order.
TQSocketDevice either creates a socket with a well known protocol family or it uses an already existing socket. In the first case, this function returns the protocol family it was constructed with. In the second case, it tries to determine the protocol family of the socket; if this fails, it returns Unknown.
Reads \fImaxlen\fR bytes from the socket into \fIdata\fR and returns the number of bytes read. Returns -1 if an error occurred. Returning 0 is not an error. For Stream sockets, 0 is returned when the remote host closes the connection. For Datagram sockets, 0 is a valid datagram size.
Sets the address of this socket to be usable by other sockets too if \fIenable\fR is TRUE, and to be used exclusively by this socket if \fIenable\fR is FALSE.
.PP
When a socket is reusable, other sockets can use the same port number (and IP address), which is generally useful. Of course other sockets cannot use the same (address,port,peer-address,peer-port) 4-tuple as this socket, so there is no risk of confusing the two TCP connections.
\fBWarning:\fR On Windows, this function should be used with care since whenever you use a TQSocketNotifier on Windows, the socket is immediately made nonblocking.
Sets the size of the operating system receive buffer to \fIsize\fR.
.PP
The operating system receive buffer size effectively limits two things: how much data can be in transit at any one moment, and how much data can be received in one iteration of the main event loop.
.PP
The default is operating system-dependent. A socket that receives large amounts of data is probably best with a buffer size of 49152.
The \fItype\fR argument must match the actual socket type; use TQSocketDevice::Stream for a reliable, connection-oriented TCP socket, or TQSocketDevice::Datagram for an unreliable, connectionless UDP socket.
Wait up to \fImsecs\fR milliseconds for more data to be available. If \fImsecs\fR is -1 the call will block indefinitely.
.PP
Returns the number of bytes available for reading, or -1 if an error occurred.
.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.