.TH "KNetwork::KStreamSocket" kde3 "11 Jun 2005" "Version Version 3.4.1" "kdecore Library" \" -*- nroff -*-
.ad l
.nh
.SH NAME
KNetwork::KStreamSocket \- Simple stream socket.  

.PP
.SH SYNOPSIS
.br
.PP
\fC#include <kstreamsocket.h>\fP
.PP
Inherits \fBKNetwork::KClientSocketBase\fP.
.PP
Inherited by \fBKNetwork::KBufferedSocket\fP.
.PP
.SS "Signals"

.in +1c
.ti -1c
.RI "void \fBtimedOut\fP ()"
.br
.in -1c
.SS "Public Member Functions"

.in +1c
.ti -1c
.RI "\fBKStreamSocket\fP (const \fBQString\fP &node=QString::null, const \fBQString\fP &service=QString::null, \fBQObject\fP *\fBparent\fP=0L, const char *\fBname\fP=0L)"
.br
.ti -1c
.RI "virtual \fB~KStreamSocket\fP ()"
.br
.ti -1c
.RI "int \fBtimeout\fP () const "
.br
.ti -1c
.RI "int \fBremainingTimeout\fP () const "
.br
.ti -1c
.RI "void \fBsetTimeout\fP (int msecs)"
.br
.ti -1c
.RI "virtual bool \fBbind\fP (const \fBQString\fP &node=QString::null, const \fBQString\fP &service=QString::null)"
.br
.ti -1c
.RI "virtual bool \fBbind\fP (const \fBKResolverEntry\fP &entry)"
.br
.ti -1c
.RI "virtual bool \fBconnect\fP (const \fBQString\fP &node=QString::null, const \fBQString\fP &service=QString::null)"
.br
.ti -1c
.RI "virtual bool \fBconnect\fP (const \fBKResolverEntry\fP &entry)"
.br
.in -1c
.SS "Friends"

.in +1c
.ti -1c
.RI "class \fBKServerSocket\fP"
.br
.in -1c
.SH "Detailed Description"
.PP 
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.
.PP
Objects of this class start, by default, on non-blocking mode. Call setBlocking if you wish to change that.
.PP
Sample usage: 
.PP
.nf
   QByteArray httpGet(const QString& hostname)
   {
     KStreamSocket socket(hostname, 'http');
     if (!socket.connect())
       return QByteArray();
     QByteArray data = socket.readAll();
     return data;
   }

.fi
.PP
.PP
Here's another sample, showing asynchronous operation: 
.PP
.nf
  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();
  }

.fi
.PP
.PP
\fBAuthor:\fP
.RS 4
Thiago Macieira <thiago.macieira@kdemail.net> 
.RE
.PP
\fBVersion:\fP
.RS 4
0.9 
.RE
.PP

.PP
Definition at line 91 of file kstreamsocket.h.
.SH "Constructor & Destructor Documentation"
.PP 
.SS "KStreamSocket::KStreamSocket (const \fBQString\fP & node = \fCQString::null\fP, const \fBQString\fP & service = \fCQString::null\fP, \fBQObject\fP * parent = \fC0L\fP, const char * name = \fC0L\fP)"
.PP
Default constructor. 
.PP
\fBParameters:\fP
.RS 4
\fInode\fP destination host 
.br
\fIservice\fP destination service to connect to 
.br
\fIparent\fP the parent \fBQObject\fP object 
.br
\fIname\fP the name of this object 
.RE
.PP

.PP
Definition at line 52 of file kstreamsocket.cpp.
.PP
References QObject::connect(), KNetwork::KClientSocketBase::localResolver(), KNetwork::KClientSocketBase::peerResolver(), KNetwork::KResolver::setFamily(), KNetwork::KResolver::setNodeName(), KNetwork::KResolver::setServiceName(), KNetwork::KClientSocketBase::setSocketOptions(), KNetwork::KSocketBase::socketOptions(), and timeout().
.SS "KStreamSocket::~\fBKStreamSocket\fP ()\fC [virtual]\fP"
.PP
Destructor. 
.PP
This closes the socket. 
.PP
Definition at line 66 of file kstreamsocket.cpp.
.SH "Member Function Documentation"
.PP 
.SS "int KStreamSocket::timeout () const"
.PP
Retrieves the timeout value (in milliseconds). 
.PP
Definition at line 72 of file kstreamsocket.cpp.
.PP
Referenced by connect(), KStreamSocket(), and remainingTimeout().
.SS "int KStreamSocket::remainingTimeout () const"
.PP
Retrieves the remaining timeout time (in milliseconds). 
.PP
This value equals \fBtimeout()\fP if there's no connection in progress. 
.PP
Definition at line 77 of file kstreamsocket.cpp.
.PP
References KNetwork::KClientSocketBase::state(), and timeout().
.PP
Referenced by connect().
.SS "void KStreamSocket::setTimeout (int msecs)"
.PP
Sets the timeout value. 
.PP
Setting this value while a connection attempt is in progress will reset the timer.
.PP
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.
.PP
\fBParameters:\fP
.RS 4
\fImsecs\fP the timeout value in milliseconds 
.RE
.PP

.PP
Definition at line 87 of file kstreamsocket.cpp.
.PP
References KNetwork::KClientSocketBase::state().
.SS "bool KStreamSocket::bind (const \fBQString\fP & node = \fCQString::null\fP, const \fBQString\fP & service = \fCQString::null\fP)\fC [virtual]\fP"
.PP
Binds this socket to the given nodename and service, or use the default ones if none are given. 
.PP
In order to bind to a service and allow the operating system to choose the interface, set \fCnode\fP to QString::null.
.PP
Reimplemented from \fBKClientSocketBase\fP.
.PP
Upon successful binding, the \fBbound\fP signal will be emitted. If an error is found, the \fBgotError\fP signal will be emitted.
.PP
\fBNote:\fP
.RS 4
Due to the internals of the name lookup and binding mechanism, some (if not most) implementations of this function do not actually bind the socket until the connection is requested (see \fBconnect\fP). They only set the values for future reference.
.RE
.PP
This function returns true on success.
.PP
\fBParameters:\fP
.RS 4
\fInode\fP the nodename 
.br
\fIservice\fP the service 
.RE
.PP

.PP
Implements \fBKNetwork::KClientSocketBase\fP.
.PP
Definition at line 95 of file kstreamsocket.cpp.
.PP
References KNetwork::KClientSocketBase::localResolver(), KNetwork::KResolver::setNodeName(), KNetwork::KResolver::setServiceName(), and KNetwork::KClientSocketBase::state().
.SS "virtual bool KNetwork::KStreamSocket::bind (const \fBKResolverEntry\fP & entry)\fC [inline, virtual]\fP"
.PP
Reimplemented from \fBKClientSocketBase\fP. 
.PP
Connect this socket to this specific address.
.PP
Unlike \fBbind(const QString&, const QString&)\fP above, this function really does bind the socket. No lookup is performed. The \fBbound\fP signal will be emitted. 
.PP
Reimplemented from \fBKNetwork::KClientSocketBase\fP.
.PP
Definition at line 169 of file kstreamsocket.h.
.SS "bool KStreamSocket::connect (const \fBQString\fP & node = \fCQString::null\fP, const \fBQString\fP & service = \fCQString::null\fP)\fC [virtual]\fP"
.PP
Reimplemented from \fBKClientSocketBase\fP. 
.PP
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).
.PP
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.
.PP
Upon successfully connecting, the \fBconnected\fP signal will be emitted. If an error is found, the \fBgotError\fP signal will be emitted.
.PP
This function also implements timeout handling.
.PP
\fBParameters:\fP
.RS 4
\fInode\fP the remote node to connect to 
.br
\fIservice\fP the service on the remote node to connect to 
.RE
.PP

.PP
Implements \fBKNetwork::KClientSocketBase\fP.
.PP
Definition at line 107 of file kstreamsocket.cpp.
.PP
References KNetwork::KSocketBase::blocking(), QObject::connect(), 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().
.SS "bool KStreamSocket::connect (const \fBKResolverEntry\fP & entry)\fC [virtual]\fP"
.PP
Unshadowing from \fBKClientSocketBase\fP. 
.PP
Reimplemented from \fBKNetwork::KClientSocketBase\fP.
.PP
Definition at line 191 of file kstreamsocket.cpp.
.SS "void KNetwork::KStreamSocket::timedOut ()\fC [signal]\fP"
.PP
This signal is emitted when a connection timeout occurs. 
.PP


.SH "Author"
.PP 
Generated automatically by Doxygen for kdecore Library from the source code.
