Gosu::MessageSocket Class Reference

Wraps an UDP socket. More...

List of all members.

Public Member Functions

 MessageSocket (SocketPort port)
 Opens a message socket for listening at the specified port.
 ~MessageSocket ()
SocketAddress address () const
 Returns the local address of the socket.
SocketPort port () const
 Returns the local port of the socket.
std::size_t maxMessageSize () const
 Returns the maximum size, in bytes, of a packet that can be sent from this socket.
void update ()
 Collects all the packets that were sent to this socket and calls onReceive for each of them.
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.

Public Attributes

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


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 37 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

boost::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 70 of file Sockets.hpp.


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