duncan
Mom and Dad were wrong!
Public Member Functions
net::Connection Class Reference

#include <connection.h>

Collaboration diagram for net::Connection:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 Connection (const std::string &address, PacketListener *lis=0, port_t port=kPort)
 Connection (port_t port=kPort)
 ~Connection ()
void send (const void *buf, size_t size, index_t peer=0, bool reliable=kReliable)
void set_listener (PacketListener *)
bool connected ()
void receive ()
unsigned int bytes_sent ()
unsigned int bytes_received ()

Detailed Description

Handles a network connection.

This class provides an abstract interface to a connection made over network sockets. The connection is opened during object construction, and closed in destruction.

Author:
Harry Slatyer
Malcolm Gill

see LICENSE


Constructor & Destructor Documentation

Connection::Connection ( const std::string &  address,
PacketListener lis = 0,
port_t  port = kPort 
)

Client-like constructor. Creates a Connection and connects to the specified server.

Parameters:
addresshostname or ip to which to connect
lispointer to listener object
portport on which to connect
Exceptions:
std::runtime_errorif ENet fails
std::runtime_errorif ENet cannot resolve the address
std::runtime_errorif ENet cannot connect to the server, or connect times out
Connection::Connection ( port_t  port = kPort)

Server-like constructor. Creates a Connection to listen locally.

Parameters:
portport on which to listen
Exceptions:
std::runtime_errorif ENet fails
Connection::~Connection ( )

Disconnects all peers.


Member Function Documentation

unsigned int Connection::bytes_received ( )

Get the number of bytes received by the host since the last call to this function.

Returns:
bytes received since last call to this function
unsigned int Connection::bytes_sent ( )

Get the number of bytes sent from the host since the last call to this function.

Returns:
bytes sent since last call to this function
void Connection::receive ( )

Processes any events sent to this Connection. Connect, disconnect and receive events are forwarded to the listener.

void Connection::send ( const void *  buf,
size_t  size,
index_t  peer = 0,
bool  reliable = kReliable 
)

Send some data to a peer.

Parameters:
bufbuffer of data
sizelength of buffer
peerindex of peer to whom to send data
Todo:
(maybe) benchmark flushing once per server frame vs once per message

The documentation for this class was generated from the following files:
 All Classes Namespaces Functions Variables Typedefs Enumerations