KDECore
KNetwork::KDatagramSocket Class Reference
A socket that operates on datagrams. More...
#include <k3datagramsocket.h>

Public Member Functions | |
virtual bool | bind (const KResolverEntry &entry) |
virtual bool | bind (const QString &node=QString(), const QString &service=QString()) |
virtual bool | connect (const KResolverEntry &entry, OpenMode mode=ReadWrite) |
virtual bool | connect (const QString &node=QString(), const QString &service=QString(), OpenMode mode=ReadWrite) |
KDatagramSocket (QObject *parent=0L) | |
virtual KDatagramPacket | receive () |
virtual qint64 | send (const KDatagramPacket &packet) |
virtual | ~KDatagramSocket () |
Protected Member Functions | |
virtual qint64 | writeData (const char *data, qint64 len, const KSocketAddress *to) |
Detailed Description
A socket that operates on datagrams.Unlike KStreamSocket, 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.
- Deprecated:
- Use KSocketFactory or KLocalSocket instead
Definition at line 182 of file k3datagramsocket.h.
Constructor & Destructor Documentation
KDatagramSocket::KDatagramSocket | ( | QObject * | parent = 0L |
) |
KDatagramSocket::~KDatagramSocket | ( | ) | [virtual] |
Member Function Documentation
bool KDatagramSocket::bind | ( | const KResolverEntry & | entry | ) | [virtual] |
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 KNetwork::KClientSocketBase.
Definition at line 95 of file k3datagramsocket.cpp.
bool KDatagramSocket::bind | ( | const QString & | node = QString() , |
|
const QString & | service = QString() | |||
) | [virtual] |
Performs host lookups.
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 KNetwork::KClientSocketBase.
Definition at line 72 of file k3datagramsocket.cpp.
bool KDatagramSocket::connect | ( | const KResolverEntry & | entry, | |
OpenMode | mode = ReadWrite | |||
) | [virtual] |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. "Connects" this socket to the given address.
Reimplemented from KNetwork::KClientSocketBase.
Definition at line 144 of file k3datagramsocket.cpp.
bool KDatagramSocket::connect | ( | const QString & | node = QString() , |
|
const QString & | service = QString() , |
|||
OpenMode | mode = ReadWrite | |||
) | [virtual] |
"Connects" 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 (see write(const char*, qint64) ).
- Note:
- Calling connect will not cause the socket to be bound. You have to call bind() explicitly.
Implements KNetwork::KClientSocketBase.
Definition at line 100 of file k3datagramsocket.cpp.
KDatagramPacket KDatagramSocket::receive | ( | ) | [virtual] |
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 149 of file k3datagramsocket.cpp.
qint64 KDatagramSocket::send | ( | const KDatagramPacket & | packet | ) | [virtual] |
Sends one datagram into the stream.
The destination address must be set if this socket has not been connected (see connect()).
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.
- Returns:
- the number of bytes written or -1 in case of error.
Definition at line 184 of file k3datagramsocket.cpp.
qint64 KDatagramSocket::writeData | ( | const char * | data, | |
qint64 | len, | |||
const KSocketAddress * | to | |||
) | [protected, virtual] |
Writes data to the socket.
Reimplemented from KSocketBase.
Reimplemented from KNetwork::KClientSocketBase.
Definition at line 189 of file k3datagramsocket.cpp.
The documentation for this class was generated from the following files: