Gosu
Public Member Functions | Public Attributes | List of all members
Gosu::MessageSocket Class Reference

Wraps an UDP socket. More...

Public Member Functions

 MessageSocket (SocketPort port)
 Opens a message socket for listening at the specified port. More...
 
 ~MessageSocket ()
 
SocketAddress address () const
 Returns the local address of the socket. More...
 
SocketPort port () const
 Returns the local port of the socket. More...
 
std::size_t maxMessageSize () const
 Returns the maximum size, in bytes, of a packet that can be sent from this socket. More...
 
void update ()
 Collects all the packets that were sent to this socket and calls onReceive for each of them. More...
 
void send (SocketAddress address, SocketPort port, const void *buffer, std::size_t size)
 Sends something to the given port of the computer identified by the address. More...
 

Public Attributes

std::tr1::function< void(SocketAddress, SocketPort, const void *, std::size_t)> onReceive
 If assigned, will be called by update for every packet received. More...
 

Detailed Description

Wraps an UDP socket.

Message sockets can send data to and receive data from arbitrary addresses. Also, message sockets send messages (packets) which are limited in size and can arrive in any order, or not at all.

Definition at line 36 of file Sockets.hpp.

Constructor & Destructor Documentation

Gosu::MessageSocket::MessageSocket ( SocketPort  port)
explicit

Opens a message socket for listening at the specified port.

Gosu::anyPort may be passed to have the message socket use a random free port.

Gosu::MessageSocket::~MessageSocket ( )

Member Function Documentation

SocketAddress Gosu::MessageSocket::address ( ) const

Returns the local address of the socket.

std::size_t Gosu::MessageSocket::maxMessageSize ( ) const

Returns the maximum size, in bytes, of a packet that can be sent from this socket.

SocketPort Gosu::MessageSocket::port ( ) const

Returns the local port of the socket.

void Gosu::MessageSocket::send ( SocketAddress  address,
SocketPort  port,
const void *  buffer,
std::size_t  size 
)

Sends something to the given port of the computer identified by the address.

void Gosu::MessageSocket::update ( )

Collects all the packets that were sent to this socket and calls onReceive for each of them.

Member Data Documentation

std::tr1::function<void (SocketAddress, SocketPort, const void*, std::size_t)> Gosu::MessageSocket::onReceive

If assigned, will be called by update for every packet received.

Definition at line 75 of file Sockets.hpp.


The documentation for this class was generated from the following file: