libkdegames/kggznet
KGGZRaw Class Reference
#include <kggzraw.h>

Detailed Description
Communication interface to raw (non-quantized) binary communication.The KGGZRaw class can be used to read and write binary data on a network stream. To use it, make the socket's file descriptor known to KGGZRaw through setNetwork, and connect the signalError signal to a slot just in case an error happens. Afterwards, read and write data at any time.
KGGZRaw implements the 'easysock' binary protocol from the GGZ Gaming Zone project. For alternative protocols, please have a look at the KGGZPacket class, or at http://dev.ggzgamingzone.org/protocols/.
From a developer point of view, this class should be used as a replacement for QDataStream on TCP/IP sockets for blocking read and write operations. It only covers the three basic data types supported by the easysock library, namely integers, characters and strings. All const char* strings are automatically converted to and from QStrings. Since the native format of serialized QStrings on QDataStream differs, the Qt behaviour can be restored with setFormat. In the context of GGZ games, this should however not be necessary.
Note: Blocking operations might freeze the GUI, so either use KGGZRaw in a separate thread only, or ensure that data can always be read (i.e. for local Unix socket operations).
Definition at line 75 of file kggzraw.h.
Public Types | |
| enum | Format { QtFormat, EasysockFormat } |
Signals | |
| void | signalError () |
Public Member Functions | |
| KGGZRaw () | |
| KGGZRaw & | operator<< (QString s) |
| KGGZRaw & | operator<< (qint8 i) |
| KGGZRaw & | operator<< (qint32 i) |
| KGGZRaw & | operator>> (QString &s) |
| KGGZRaw & | operator>> (qint8 &i) |
| KGGZRaw & | operator>> (qint32 &i) |
| void | setFormat (Format format) |
| void | setNetwork (int fd) |
| ~KGGZRaw () | |
Member Enumeration Documentation
| enum KGGZRaw::Format |
Data serialization format.
The default format is EasysockFormat.
Constructor & Destructor Documentation
| KGGZRaw::KGGZRaw | ( | ) |
Constructor.
Creates a new KGGZRaw object. It will remain unusable unless setNetwork is called.
Definition at line 50 of file kggzraw.cpp.
| KGGZRaw::~KGGZRaw | ( | ) |
Member Function Documentation
Definition at line 182 of file kggzraw.cpp.
| KGGZRaw & KGGZRaw::operator<< | ( | qint8 | i | ) |
Definition at line 172 of file kggzraw.cpp.
| KGGZRaw & KGGZRaw::operator<< | ( | qint32 | i | ) |
Definition at line 162 of file kggzraw.cpp.
Definition at line 138 of file kggzraw.cpp.
| KGGZRaw & KGGZRaw::operator>> | ( | qint8 & | i | ) |
Definition at line 126 of file kggzraw.cpp.
| KGGZRaw & KGGZRaw::operator>> | ( | qint32 & | i | ) |
Definition at line 114 of file kggzraw.cpp.
| void KGGZRaw::setFormat | ( | Format | format | ) |
Changes the serialization format.
The format of the datatypes on the wire can be influenced by calling this method. However, this should not be necessary in most cases, since the EasysockFormat is used by default.
- Parameters:
-
format Format to use for data serialization
Definition at line 66 of file kggzraw.cpp.
| void KGGZRaw::setNetwork | ( | int | fd | ) |
Specifies the socket file descriptor to use.
This function must be called exactly once before a KGGZRaw object can be used. Calling it more than once will result in an error. The socket must be a TCP/IP socket and already be opened. Usually, game clients will use KGGZRaw on the socket to the game server as returned by KGGZMod's Module object.
- Parameters:
-
fd File descriptor of the underlying TCP/IP socket
Definition at line 71 of file kggzraw.cpp.
| void KGGZRaw::signalError | ( | ) | [signal] |
An error has occurred.
The game should destroy the KGGZRaw object and disable all networking activities associated with it.
The documentation for this class was generated from the following files:
KDE 4.1 API Reference