\section{KNetwork::KDatagram\-Socket Class Reference}
\label{classKNetwork_1_1KDatagramSocket}\index{KNetwork::KDatagramSocket@{KNetwork::KDatagramSocket}}
A socket that operates on datagrams.  


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

Inheritance diagram for KNetwork::KDatagram\-Socket:\begin{figure}[H]
\begin{center}
\leavevmode
\includegraphics[width=150pt]{classKNetwork_1_1KDatagramSocket__inherit__graph}
\end{center}
\end{figure}
Collaboration diagram for KNetwork::KDatagram\-Socket:\begin{figure}[H]
\begin{center}
\leavevmode
\includegraphics[width=150pt]{classKNetwork_1_1KDatagramSocket__coll__graph}
\end{center}
\end{figure}
\subsection*{Public Member Functions}
\begin{CompactItemize}
\item 
{\bf KDatagram\-Socket} ({\bf QObject} $\ast${\bf parent}=0L, const char $\ast${\bf name}=0L)
\item 
virtual {\bf $\sim$KDatagram\-Socket} ()
\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)
\item 
virtual {\bf KDatagram\-Packet} {\bf receive} ()
\item 
virtual Q\_\-LONG {\bf send} (const {\bf KDatagram\-Packet} \&packet)
\end{CompactItemize}


\subsection{Detailed Description}
A socket that operates on datagrams. 

Unlike {\bf KStream\-Socket}{\rm (p.\,\pageref{classKNetwork_1_1KStreamSocket})}, which operates on a connection-based stream socket (generally TCP), this class and its descendants operates on datagrams, which are normally connectionless.

This class in specific provides easy access to the system's connectionless SOCK\_\-DGRAM sockets.

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




Definition at line 180 of file kdatagramsocket.h.

\subsection{Constructor \& Destructor Documentation}
\index{KNetwork::KDatagramSocket@{KNetwork::KDatagram\-Socket}!KDatagramSocket@{KDatagramSocket}}
\index{KDatagramSocket@{KDatagramSocket}!KNetwork::KDatagramSocket@{KNetwork::KDatagram\-Socket}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}KDatagram\-Socket::KDatagram\-Socket ({\bf QObject} $\ast$ {\em parent} = {\tt 0L}, const char $\ast$ {\em name} = {\tt 0L})}\label{classKNetwork_1_1KDatagramSocket_a0}


Default constructor. 



Definition at line 44 of file kdatagramsocket.cpp.

References QObject::connect(), KNetwork::KClient\-Socket\-Base::host\-Found(), KNetwork::KClient\-Socket\-Base::local\-Resolver(), KNetwork::KClient\-Socket\-Base::peer\-Resolver(), KNetwork::KResolver::set\-Family(), KNetwork::KResolver::set\-Flags(), and KNetwork::KResolver::set\-Socket\-Type().\index{KNetwork::KDatagramSocket@{KNetwork::KDatagram\-Socket}!~KDatagramSocket@{$\sim$KDatagramSocket}}
\index{~KDatagramSocket@{$\sim$KDatagramSocket}!KNetwork::KDatagramSocket@{KNetwork::KDatagram\-Socket}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}KDatagram\-Socket::$\sim${\bf KDatagram\-Socket} ()\hspace{0.3cm}{\tt  [virtual]}}\label{classKNetwork_1_1KDatagramSocket_a1}


Destructor. 

This closes the socket. 

Definition at line 62 of file kdatagramsocket.cpp.

\subsection{Member Function Documentation}
\index{KNetwork::KDatagramSocket@{KNetwork::KDatagram\-Socket}!bind@{bind}}
\index{bind@{bind}!KNetwork::KDatagramSocket@{KNetwork::KDatagram\-Socket}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}bool KDatagram\-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_1KDatagramSocket_a2}


Binds this socket to the given address. 

If the socket is blocking, the socket will be bound when this function returns.

Note that binding a socket is not necessary to be able to send datagrams. Some protocol families will use anonymous source addresses, while others will allocate an address automatically. 

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

Definition at line 69 of file kdatagramsocket.cpp.

References KNetwork::KResolver::cancel(), KNetwork::KClient\-Socket\-Base::local\-Resolver(), KNetwork::KClient\-Socket\-Base::lookup(), KNetwork::KResolver::set\-Address(), and KNetwork::KClient\-Socket\-Base::state().\index{KNetwork::KDatagramSocket@{KNetwork::KDatagram\-Socket}!bind@{bind}}
\index{bind@{bind}!KNetwork::KDatagramSocket@{KNetwork::KDatagram\-Socket}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}virtual bool KNetwork::KDatagram\-Socket::bind (const {\bf KResolver\-Entry} \& {\em entry})\hspace{0.3cm}{\tt  [inline, virtual]}}\label{classKNetwork_1_1KDatagramSocket_a3}


This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Binds this socket to the given address. 

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

Definition at line 215 of file kdatagramsocket.h.\index{KNetwork::KDatagramSocket@{KNetwork::KDatagram\-Socket}!connect@{connect}}
\index{connect@{connect}!KNetwork::KDatagramSocket@{KNetwork::KDatagram\-Socket}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}bool KDatagram\-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_1KDatagramSocket_a4}


\char`\"{}Connects\char`\"{} this socket to the given address. 

Note that connecting a datagram socket normally does not establish a permanent connection with the peer nor normally returns an error in case of failure.

Connecting means only to designate the given address as the default destination address for datagrams sent without destination addresses (write\-Block(const char$\ast$, Q\_\-LONG).

\begin{Desc}
\item[Note:]Calling connect will not cause the socket to be bound. You have to call {\bf bind}{\rm (p.\,\pageref{classKNetwork_1_1KDatagramSocket_a2})} explicitly. \end{Desc}


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

Definition at line 92 of file kdatagramsocket.cpp.

References KNetwork::KClient\-Socket\-Base::lookup(), KNetwork::KClient\-Socket\-Base::peer\-Resolver(), KNetwork::KResolver::set\-Address(), KNetwork::KClient\-Socket\-Base::set\-State(), KNetwork::KClient\-Socket\-Base::state(), and KNetwork::KClient\-Socket\-Base::state\-Changed().\index{KNetwork::KDatagramSocket@{KNetwork::KDatagram\-Socket}!connect@{connect}}
\index{connect@{connect}!KNetwork::KDatagramSocket@{KNetwork::KDatagram\-Socket}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}virtual bool KNetwork::KDatagram\-Socket::connect (const {\bf KResolver\-Entry} \& {\em entry})\hspace{0.3cm}{\tt  [inline, virtual]}}\label{classKNetwork_1_1KDatagramSocket_a5}


This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

\char`\"{}Connects\char`\"{} this socket to the given address. 

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

Definition at line 237 of file kdatagramsocket.h.\index{KNetwork::KDatagramSocket@{KNetwork::KDatagram\-Socket}!receive@{receive}}
\index{receive@{receive}!KNetwork::KDatagramSocket@{KNetwork::KDatagram\-Socket}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}{\bf KDatagram\-Packet} KDatagram\-Socket::receive ()\hspace{0.3cm}{\tt  [virtual]}}\label{classKNetwork_1_1KDatagramSocket_a6}


Receives one datagram from the stream. 

The reading process is guaranteed to be atomical and not lose data from the packet.

If nothing could be read, a null object will be returned. 

Definition at line 134 of file kdatagramsocket.cpp.

References KNetwork::KSocket\-Base::blocking(), KNetwork::KClient\-Socket\-Base::bytes\-Available(), KNetwork::KClient\-Socket\-Base::got\-Error(), KNetwork::KClient\-Socket\-Base::read\-Block(), KNetwork::KActive\-Socket\-Base::set\-Error(), KNetwork::KSocket\-Base::socket\-Device(), and KNetwork::KSocket\-Device::wait\-For\-More().\index{KNetwork::KDatagramSocket@{KNetwork::KDatagram\-Socket}!send@{send}}
\index{send@{send}!KNetwork::KDatagramSocket@{KNetwork::KDatagram\-Socket}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}Q\_\-LONG KDatagram\-Socket::send (const {\bf KDatagram\-Packet} \& {\em packet})\hspace{0.3cm}{\tt  [virtual]}}\label{classKNetwork_1_1KDatagramSocket_a7}


Sends one datagram into the stream. 

The destination address must be set if this socket has not been connected (see {\bf connect}{\rm (p.\,\pageref{classKNetwork_1_1KDatagramSocket_a4})}).

The data in this packet will be sent only in one single datagram. If the system cannot send it like that, this function will fail. So, please take into consideration the datagram size limits.

\begin{Desc}
\item[Returns:]the number of bytes written or -1 in case of error. \end{Desc}


Definition at line 168 of file kdatagramsocket.cpp.

References KNetwork::KClient\-Socket\-Base::write\-Block().

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