\section{KNetwork::KStream\-Socket Class Reference}
\label{classKNetwork_1_1KStreamSocket}\index{KNetwork::KStreamSocket@{KNetwork::KStreamSocket}}
Simple stream socket.  


{\tt \#include $<$kstreamsocket.h$>$}

Inheritance diagram for KNetwork::KStream\-Socket:\begin{figure}[H]
\begin{center}
\leavevmode
\includegraphics[width=150pt]{classKNetwork_1_1KStreamSocket__inherit__graph}
\end{center}
\end{figure}
Collaboration diagram for KNetwork::KStream\-Socket:\begin{figure}[H]
\begin{center}
\leavevmode
\includegraphics[width=150pt]{classKNetwork_1_1KStreamSocket__coll__graph}
\end{center}
\end{figure}
\subsection*{Signals}
\begin{CompactItemize}
\item 
void {\bf timed\-Out} ()
\end{CompactItemize}
\subsection*{Public Member Functions}
\begin{CompactItemize}
\item 
{\bf KStream\-Socket} (const {\bf QString} \&node=QString::null, const {\bf QString} \&service=QString::null, {\bf QObject} $\ast${\bf parent}=0L, const char $\ast${\bf name}=0L)
\item 
virtual {\bf $\sim$KStream\-Socket} ()
\item 
int {\bf timeout} () const 
\item 
int {\bf remaining\-Timeout} () const 
\item 
void {\bf set\-Timeout} (int msecs)
\item 
virtual bool {\bf bind} (const {\bf QString} \&node=QString::null, const {\bf QString} \&service=QString::null)
\item 
virtual bool {\bf bind} (const {\bf KResolver\-Entry} \&entry)
\item 
virtual bool {\bf connect} (const {\bf QString} \&node=QString::null, const {\bf QString} \&service=QString::null)
\item 
virtual bool {\bf connect} (const {\bf KResolver\-Entry} \&entry)
\end{CompactItemize}
\subsection*{Friends}
\begin{CompactItemize}
\item 
class {\bf KServer\-Socket}\label{classKNetwork_1_1KStreamSocket_n0}

\end{CompactItemize}


\subsection{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 set\-Blocking if you wish to change that.

Sample usage: 

\footnotesize\begin{verbatim}   QByteArray httpGet(const QString& hostname)
   {
     KStreamSocket socket(hostname, "http");
     if (!socket.connect())
       return QByteArray();
     QByteArray data = socket.readAll();
     return data;
   }
\end{verbatim}
\normalsize


Here's another sample, showing asynchronous operation: 

\footnotesize\begin{verbatim}  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();
  }
\end{verbatim}
\normalsize


\begin{Desc}
\item[Author:]Thiago Macieira $<${\tt thiago.macieira@kdemail.net}$>$ \end{Desc}
\begin{Desc}
\item[Version:]0.9 \end{Desc}




Definition at line 91 of file kstreamsocket.h.

\subsection{Constructor \& Destructor Documentation}
\index{KNetwork::KStreamSocket@{KNetwork::KStream\-Socket}!KStreamSocket@{KStreamSocket}}
\index{KStreamSocket@{KStreamSocket}!KNetwork::KStreamSocket@{KNetwork::KStream\-Socket}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}KStream\-Socket::KStream\-Socket (const {\bf QString} \& {\em node} = {\tt QString::null}, const {\bf QString} \& {\em service} = {\tt QString::null}, {\bf QObject} $\ast$ {\em parent} = {\tt 0L}, const char $\ast$ {\em name} = {\tt 0L})}\label{classKNetwork_1_1KStreamSocket_a0}


Default constructor. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em node}]destination host \item[{\em service}]destination service to connect to \item[{\em parent}]the parent {\bf QObject} object \item[{\em name}]the name of this object \end{description}
\end{Desc}


Definition at line 52 of file kstreamsocket.cpp.

References QObject::connect(), KNetwork::KClient\-Socket\-Base::local\-Resolver(), KNetwork::KClient\-Socket\-Base::peer\-Resolver(), KNetwork::KResolver::set\-Family(), KNetwork::KResolver::set\-Node\-Name(), KNetwork::KResolver::set\-Service\-Name(), KNetwork::KClient\-Socket\-Base::set\-Socket\-Options(), KNetwork::KSocket\-Base::socket\-Options(), and timeout().\index{KNetwork::KStreamSocket@{KNetwork::KStream\-Socket}!~KStreamSocket@{$\sim$KStreamSocket}}
\index{~KStreamSocket@{$\sim$KStreamSocket}!KNetwork::KStreamSocket@{KNetwork::KStream\-Socket}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}KStream\-Socket::$\sim${\bf KStream\-Socket} ()\hspace{0.3cm}{\tt  [virtual]}}\label{classKNetwork_1_1KStreamSocket_a1}


Destructor. 

This closes the socket. 

Definition at line 66 of file kstreamsocket.cpp.

\subsection{Member Function Documentation}
\index{KNetwork::KStreamSocket@{KNetwork::KStream\-Socket}!timeout@{timeout}}
\index{timeout@{timeout}!KNetwork::KStreamSocket@{KNetwork::KStream\-Socket}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}int KStream\-Socket::timeout () const}\label{classKNetwork_1_1KStreamSocket_a2}


Retrieves the timeout value (in milliseconds). 



Definition at line 72 of file kstreamsocket.cpp.

Referenced by connect(), KStream\-Socket(), and remaining\-Timeout().\index{KNetwork::KStreamSocket@{KNetwork::KStream\-Socket}!remainingTimeout@{remainingTimeout}}
\index{remainingTimeout@{remainingTimeout}!KNetwork::KStreamSocket@{KNetwork::KStream\-Socket}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}int KStream\-Socket::remaining\-Timeout () const}\label{classKNetwork_1_1KStreamSocket_a3}


Retrieves the remaining timeout time (in milliseconds). 

This value equals {\bf timeout()}{\rm (p.\,\pageref{classKNetwork_1_1KStreamSocket_a2})} if there's no connection in progress. 

Definition at line 77 of file kstreamsocket.cpp.

References KNetwork::KClient\-Socket\-Base::state(), and timeout().

Referenced by connect().\index{KNetwork::KStreamSocket@{KNetwork::KStream\-Socket}!setTimeout@{setTimeout}}
\index{setTimeout@{setTimeout}!KNetwork::KStreamSocket@{KNetwork::KStream\-Socket}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}void KStream\-Socket::set\-Timeout (int {\em msecs})}\label{classKNetwork_1_1KStreamSocket_a4}


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.

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em msecs}]the timeout value in milliseconds \end{description}
\end{Desc}


Definition at line 87 of file kstreamsocket.cpp.

References KNetwork::KClient\-Socket\-Base::state().\index{KNetwork::KStreamSocket@{KNetwork::KStream\-Socket}!bind@{bind}}
\index{bind@{bind}!KNetwork::KStreamSocket@{KNetwork::KStream\-Socket}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}bool KStream\-Socket::bind (const {\bf QString} \& {\em node} = {\tt QString::null}, const {\bf QString} \& {\em service} = {\tt QString::null})\hspace{0.3cm}{\tt  [virtual]}}\label{classKNetwork_1_1KStreamSocket_a5}


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 {\tt node} to QString::null.

Reimplemented from {\bf KClient\-Socket\-Base}{\rm (p.\,\pageref{classKNetwork_1_1KClientSocketBase})}.

Upon successful binding, the {\bf bound}{\rm (p.\,\pageref{classKNetwork_1_1KClientSocketBase_l3})} signal will be emitted. If an error is found, the {\bf got\-Error}{\rm (p.\,\pageref{classKNetwork_1_1KClientSocketBase_l1})} signal will be emitted.

\begin{Desc}
\item[Note:]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 {\bf connect}{\rm (p.\,\pageref{classKNetwork_1_1KStreamSocket_a7})}). They only set the values for future reference.\end{Desc}
This function returns true on success.

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em node}]the nodename \item[{\em service}]the service \end{description}
\end{Desc}


Implements {\bf KNetwork::KClient\-Socket\-Base} {\rm (p.\,\pageref{classKNetwork_1_1KClientSocketBase_a10})}.

Definition at line 95 of file kstreamsocket.cpp.

References KNetwork::KClient\-Socket\-Base::local\-Resolver(), KNetwork::KResolver::set\-Node\-Name(), KNetwork::KResolver::set\-Service\-Name(), and KNetwork::KClient\-Socket\-Base::state().\index{KNetwork::KStreamSocket@{KNetwork::KStream\-Socket}!bind@{bind}}
\index{bind@{bind}!KNetwork::KStreamSocket@{KNetwork::KStream\-Socket}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}virtual bool KNetwork::KStream\-Socket::bind (const {\bf KResolver\-Entry} \& {\em entry})\hspace{0.3cm}{\tt  [inline, virtual]}}\label{classKNetwork_1_1KStreamSocket_a6}


Reimplemented from {\bf KClient\-Socket\-Base}{\rm (p.\,\pageref{classKNetwork_1_1KClientSocketBase})}. 

Connect this socket to this specific address.

Unlike {\bf bind(const QString\&, const QString\&)}{\rm (p.\,\pageref{classKNetwork_1_1KStreamSocket_a5})} above, this function really does bind the socket. No lookup is performed. The {\bf bound}{\rm (p.\,\pageref{classKNetwork_1_1KClientSocketBase_l3})} signal will be emitted. 

Reimplemented from {\bf KNetwork::KClient\-Socket\-Base} {\rm (p.\,\pageref{classKNetwork_1_1KClientSocketBase_a11})}.

Definition at line 169 of file kstreamsocket.h.\index{KNetwork::KStreamSocket@{KNetwork::KStream\-Socket}!connect@{connect}}
\index{connect@{connect}!KNetwork::KStreamSocket@{KNetwork::KStream\-Socket}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}bool KStream\-Socket::connect (const {\bf QString} \& {\em node} = {\tt QString::null}, const {\bf QString} \& {\em service} = {\tt QString::null})\hspace{0.3cm}{\tt  [virtual]}}\label{classKNetwork_1_1KStreamSocket_a7}


Reimplemented from {\bf KClient\-Socket\-Base}{\rm (p.\,\pageref{classKNetwork_1_1KClientSocketBase})}. 

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 (No\-Error, meaning the connection is completed, or In\-Progress).

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 {\bf connected}{\rm (p.\,\pageref{classKNetwork_1_1KClientSocketBase_l5})} signal will be emitted. If an error is found, the {\bf got\-Error}{\rm (p.\,\pageref{classKNetwork_1_1KClientSocketBase_l1})} signal will be emitted.

This function also implements timeout handling.

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em node}]the remote node to connect to \item[{\em service}]the service on the remote node to connect to \end{description}
\end{Desc}


Implements {\bf KNetwork::KClient\-Socket\-Base} {\rm (p.\,\pageref{classKNetwork_1_1KClientSocketBase_a12})}.

Definition at line 107 of file kstreamsocket.cpp.

References KNetwork::KSocket\-Base::blocking(), QObject::connect(), KNetwork::KSocket\-Base::error(), KNetwork::KClient\-Socket\-Base::got\-Error(), KNetwork::KClient\-Socket\-Base::host\-Found(), KNetwork::KClient\-Socket\-Base::lookup(), KNetwork::KClient\-Socket\-Base::peer\-Resolver(), KNetwork::KSocket\-Device::poll(), remaining\-Timeout(), KNetwork::KSocket\-Base::set\-Blocking(), KNetwork::KActive\-Socket\-Base::set\-Error(), KNetwork::KResolver::set\-Node\-Name(), KNetwork::KResolver::set\-Service\-Name(), KNetwork::KSocket\-Base::socket\-Device(), KNetwork::KResolver::start(), KNetwork::KClient\-Socket\-Base::state(), and timeout().\index{KNetwork::KStreamSocket@{KNetwork::KStream\-Socket}!connect@{connect}}
\index{connect@{connect}!KNetwork::KStreamSocket@{KNetwork::KStream\-Socket}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}bool KStream\-Socket::connect (const {\bf KResolver\-Entry} \& {\em entry})\hspace{0.3cm}{\tt  [virtual]}}\label{classKNetwork_1_1KStreamSocket_a8}


Unshadowing from {\bf KClient\-Socket\-Base}{\rm (p.\,\pageref{classKNetwork_1_1KClientSocketBase})}. 



Reimplemented from {\bf KNetwork::KClient\-Socket\-Base} {\rm (p.\,\pageref{classKNetwork_1_1KClientSocketBase_a13})}.

Definition at line 191 of file kstreamsocket.cpp.\index{KNetwork::KStreamSocket@{KNetwork::KStream\-Socket}!timedOut@{timedOut}}
\index{timedOut@{timedOut}!KNetwork::KStreamSocket@{KNetwork::KStream\-Socket}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}void KNetwork::KStream\-Socket::timed\-Out ()\hspace{0.3cm}{\tt  [signal]}}\label{classKNetwork_1_1KStreamSocket_l0}


This signal is emitted when a connection timeout occurs. 



The documentation for this class was generated from the following files:\begin{CompactItemize}
\item 
kstreamsocket.h\item 
kstreamsocket.cpp\end{CompactItemize}
