UPD socket implementation. More...
#include <Radiant/UDPSocket.hpp>
Public Member Functions | |
| bool | close () |
| Closes the socket. More... | |
| bool | isOpen () const |
| Returns true if the socket is open. More... | |
| int | openClient (const char *host, int port) |
| Opens a client socket for sending packets to given address. More... | |
| int | openServer (int port) |
| Opens a local server socket. More... | |
| virtual int | read (void *buffer, int bytes, bool waitfordata) |
| Reads datagram packets from the socket. More... | |
| virtual int | read (void *buffer, int bytes, bool waitfordata, bool readAll) |
| Reads datagram packets from the socket. More... | |
| bool | setReceiveBufferSize (size_t bytes) |
| Sets size of receive buffer. More... | |
| UDPSocket () | |
| Constructor. | |
| UDPSocket (int fd) | |
| Constructs a new UDP socket and initializes it to the given file descriptor. More... | |
| virtual int | write (const void *data, int bytes) |
| Writes one datagram packet to the socket. More... | |
| ~UDPSocket () | |
| Destructor. | |
Public Member Functions inherited from Radiant::BinaryStream | |
| BinaryStream () | |
| Constructor. | |
| virtual bool | isHungUp () const |
| Returns true if the stream has been closed. More... | |
| virtual bool | isPendingInput (unsigned int waitMicroSeconds=0) |
| Returns true if the stream has at least one byte waiting to be read; otherwise returns false. More... | |
| virtual | ~BinaryStream () |
| Destructor. | |
UPD socket implementation.
UDP is an unreliable socket type, where data is move in datagram packages.
Packages have some limited maximum size which depends on the network, and can only be deduced dynamically in the run-time. Usually the maximum packet sizes are in the range 4-8kb.
| Radiant::UDPSocket::UDPSocket | ( | int | fd | ) |
Constructs a new UDP socket and initializes it to the given file descriptor.
| fd | File descriptor for the socket |
|
virtual |
Closes the socket.
Reimplemented from Radiant::BinaryStream.
|
virtual |
Returns true if the socket is open.
Does not make much sense in the case of UDPSockets.
Reimplemented from Radiant::BinaryStream.
| int Radiant::UDPSocket::openClient | ( | const char * | host, |
| int | port | ||
| ) |
Opens a client socket for sending packets to given address.
| host | The host address. On UNIX you can use both numeric (192.168.0.12), and human-readable (www.multitouch.fi) network names, while on Windows you can only use numeric names for the time being. |
| port | The port number to listen to |
| int Radiant::UDPSocket::openServer | ( | int | port | ) |
Opens a local server socket.
This socket is generally good for listening to incoming messages.
| port | The port number to listen to |
|
virtual |
Reads datagram packets from the socket.
| buffer | buffer to write to |
| bytes | maximum bytes to read |
| waitfordata | blocks until there is something to read |
Implements Radiant::BinaryStream.
|
virtual |
Reads datagram packets from the socket.
| buffer | buffer to write to |
| bytes | maximum bytes to read |
| waitfordata | blocks until there is something to read |
| bool Radiant::UDPSocket::setReceiveBufferSize | ( | size_t | bytes | ) |
Sets size of receive buffer.
| bytes | Requested number of bytes for the receiving buffer |
|
virtual |
Writes one datagram packet to the socket.
| data | Data to write |
| bytes | How many bytes are requested to write |
Implements Radiant::BinaryStream.