All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Pages
Radiant::UDPSocket Class Reference

UPD socket implementation. More...

#include <Radiant/UDPSocket.hpp>

Inheritance diagram for Radiant::UDPSocket:
Radiant::BinaryStream

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.
 

Detailed Description

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.

See Also
TCPSocket

Constructor & Destructor Documentation

Radiant::UDPSocket::UDPSocket ( int  fd)

Constructs a new UDP socket and initializes it to the given file descriptor.

Parameters
fdFile descriptor for the socket

Member Function Documentation

bool Radiant::UDPSocket::close ( )
virtual

Closes the socket.

Returns
True if the socket was succesfully closed.

Reimplemented from Radiant::BinaryStream.

bool Radiant::UDPSocket::isOpen ( ) const
virtual

Returns true if the socket is open.

Does not make much sense in the case of UDPSockets.

Returns
True if the socket is open.

Reimplemented from Radiant::BinaryStream.

int Radiant::UDPSocket::openClient ( const char *  host,
int  port 
)

Opens a client socket for sending packets to given address.

Parameters
hostThe 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.
portThe port number to listen to
Returns
Zero on success, otherwise an error code
int Radiant::UDPSocket::openServer ( int  port)

Opens a local server socket.

This socket is generally good for listening to incoming messages.

Parameters
portThe port number to listen to
Returns
Zero on success, otherwise an error code
virtual int Radiant::UDPSocket::read ( void *  buffer,
int  bytes,
bool  waitfordata 
)
virtual

Reads datagram packets from the socket.

Parameters
bufferbuffer to write to
bytesmaximum bytes to read
waitfordatablocks until there is something to read
Returns
The number of bytes read is returned. If there was nothing to read, then zero is returned.

Implements Radiant::BinaryStream.

virtual int Radiant::UDPSocket::read ( void *  buffer,
int  bytes,
bool  waitfordata,
bool  readAll 
)
virtual

Reads datagram packets from the socket.

Parameters
bufferbuffer to write to
bytesmaximum bytes to read
waitfordatablocks until there is something to read
Returns
The number of bytes read is returned. If there was nothing to read, then zero is returned.
bool Radiant::UDPSocket::setReceiveBufferSize ( size_t  bytes)

Sets size of receive buffer.

Parameters
bytesRequested number of bytes for the receiving buffer
Returns
True if the size of the receive buffer was succusfully updated
virtual int Radiant::UDPSocket::write ( const void *  data,
int  bytes 
)
virtual

Writes one datagram packet to the socket.

Parameters
dataData to write
bytesHow many bytes are requested to write
Returns
The number of bytes written is returned.

Implements Radiant::BinaryStream.