KNetwork::KStreamSocket Class Reference
Simple stream socket. More...
#include <kstreamsocket.h>
Inheritance diagram for KNetwork::KStreamSocket:

Signals | |
void | timedOut () |
Public Member Functions | |
KStreamSocket (const QString &node=QString::null, const QString &service=QString::null, QObject *parent=0L, const char *name=0L) | |
virtual | ~KStreamSocket () |
int | timeout () const |
int | remainingTimeout () const |
void | setTimeout (int msecs) |
virtual bool | bind (const QString &node=QString::null, const QString &service=QString::null) |
virtual bool | bind (const KResolverEntry &entry) |
virtual bool | connect (const QString &node=QString::null, const QString &service=QString::null) |
virtual bool | connect (const KResolverEntry &entry) |
Friends | |
class | KServerSocket |
Detailed Description
Simple stream socket.This class provides functionality to creating unbuffered, stream sockets. In the case of Internet (IP) sockets, this class creates and uses TCP/IP sockets.
Objects of this class start, by default, on non-blocking mode. Call setBlocking if you wish to change that.
Sample usage:
QByteArray httpGet(const QString& hostname) { KStreamSocket socket(hostname, "http"); if (!socket.connect()) return QByteArray(); QByteArray data = socket.readAll(); return data; }
Here's another sample, showing asynchronous operation:
DataRetriever::DataRetriever(const QString& hostname, const QString& port) : socket(hostname, port) { // connect signals to our slots QObject::connect(&socket, SIGNAL(connected(const KResolverEntry&)), this, SLOT(slotSocketConnected())); QObject::connect(&socket, SIGNAL(gotError(int)), this, SLOT(slotSocketError(int))); QObject::connect(&socket, SIGNAL(readyRead()), this, SLOT(slotSocketReadyToRead())); QObject::connect(&socket, SIGNAL(readyWrite()), this, SLOT(slotSocketReadyToWrite())); // set non-blocking mode in order to work asynchronously socket.setBlocking(false); // turn on signal emission socket.enableRead(true); socket.enableWrite(true); // start connecting socket.connect(); }
- Author:
- Thiago Macieira <thiago.macieira@kdemail.net>
- Version:
- 0.9
Definition at line 91 of file kstreamsocket.h.
Constructor & Destructor Documentation
|
Default constructor.
Definition at line 52 of file kstreamsocket.cpp. References KNetwork::KClientSocketBase::localResolver(), KNetwork::KClientSocketBase::peerResolver(), KNetwork::KResolver::setFamily(), KNetwork::KResolver::setNodeName(), KNetwork::KResolver::setServiceName(), KNetwork::KClientSocketBase::setSocketOptions(), KNetwork::KSocketBase::socketOptions(), and timeout(). |
|
Destructor. This closes the socket. Definition at line 66 of file kstreamsocket.cpp. |
Member Function Documentation
|
Retrieves the timeout value (in milliseconds).
Definition at line 72 of file kstreamsocket.cpp. Referenced by connect(), KStreamSocket(), and remainingTimeout(). |
|
Retrieves the remaining timeout time (in milliseconds). This value equals timeout() if there's no connection in progress. Definition at line 77 of file kstreamsocket.cpp. References KNetwork::KClientSocketBase::state(), and timeout(). Referenced by connect(). |
|
Sets the timeout value. Setting this value while a connection attempt is in progress will reset the timer. Please note that the timeout value is valid for the connection attempt only. No other operations are timed against this value -- including the name lookup associated.
Definition at line 87 of file kstreamsocket.cpp. References KNetwork::KClientSocketBase::state(). |
|
Binds this socket to the given nodename and service, or use the default ones if none are given.
In order to bind to a service and allow the operating system to choose the interface, set Reimplemented from KClientSocketBase. Upon successful binding, the bound signal will be emitted. If an error is found, the gotError signal will be emitted.
Implements KNetwork::KClientSocketBase. Definition at line 95 of file kstreamsocket.cpp. References KNetwork::KClientSocketBase::localResolver(), KNetwork::KResolver::setNodeName(), KNetwork::KResolver::setServiceName(), and KNetwork::KClientSocketBase::state(). |
|
Reimplemented from KClientSocketBase. Connect this socket to this specific address. Unlike bind(const QString&, const QString&) above, this function really does bind the socket. No lookup is performed. The bound signal will be emitted. Reimplemented from KNetwork::KClientSocketBase. Definition at line 169 of file kstreamsocket.h. |
|
Reimplemented from KClientSocketBase. Attempts to connect to the these hostname and service, or use the default ones if none are given. If a connection attempt is already in progress, check on its state and set the error status (NoError, meaning the connection is completed, or InProgress). If the blocking mode for this object is on, this function will only return when all the resolved peer addresses have been tried or when a connection is established. Upon successfully connecting, the connected signal will be emitted. If an error is found, the gotError signal will be emitted. This function also implements timeout handling.
Implements KNetwork::KClientSocketBase. Definition at line 107 of file kstreamsocket.cpp. References KNetwork::KSocketBase::blocking(), KNetwork::KSocketBase::error(), KNetwork::KClientSocketBase::gotError(), KNetwork::KClientSocketBase::hostFound(), KNetwork::KClientSocketBase::lookup(), KNetwork::KClientSocketBase::peerResolver(), KNetwork::KSocketDevice::poll(), remainingTimeout(), KNetwork::KSocketBase::setBlocking(), KNetwork::KActiveSocketBase::setError(), KNetwork::KResolver::setNodeName(), KNetwork::KResolver::setServiceName(), KNetwork::KSocketBase::socketDevice(), KNetwork::KResolver::start(), KNetwork::KClientSocketBase::state(), and timeout(). |
|
Unshadowing from KClientSocketBase.
Reimplemented from KNetwork::KClientSocketBase. Definition at line 191 of file kstreamsocket.cpp. |
|
This signal is emitted when a connection timeout occurs.
|
The documentation for this class was generated from the following files: