Public Member Functions | Static Public Member Functions | Static Public Attributes | Private Attributes | Static Private Attributes | List of all members
Network Class Reference

Public Member Functions

 Network (int peer_count, int channel_limit, uint32_t max_incoming_bandwidth, uint32_t max_outgoing_bandwidth, ENetAddress *address, bool change_port_if_bound=false)
 Constructor that just initialises this object (esp. More...
virtual ~Network ()
 Destructor. More...
ENetPeer * connectTo (const ENetAddress &address)
void sendRawPacket (const BareNetworkString &buffer, const SocketAddress &dst)
 Sends a packet whithout ENet adding its headers. More...
int receiveRawPacket (char *buffer, int buf_len, SocketAddress *sender, int max_tries=-1)
 Receives a packet directly from the network interface and filter its address. More...
void broadcastPacket (NetworkString *data, bool reliable=true)
 Broadcasts a packet to all peers. More...
uint16_t getPort () const
ENetHost * getENetHost ()
 Returns a pointer to the ENet host object. More...
bool isIPv6Socket ()

Static Public Member Functions

static void openLog ()
static void logPacket (const BareNetworkString &ns, bool incoming)
 Log packets into a file. More...
static void closeLog ()

Static Public Attributes

static bool m_connection_debug = false

Private Attributes

ENetHost * m_host
 ENet host interfacing sockets. More...
uint16_t m_port
bool m_ipv6_socket

Static Private Attributes

static Synchronised< FILE * > m_log_file
 Where to log packets. More...

Constructor & Destructor Documentation

◆ Network()

Network::Network ( int  peer_count,
int  channel_limit,
uint32_t  max_incoming_bandwidth,
uint32_t  max_outgoing_bandwidth,
ENetAddress *  address,
bool  change_port_if_bound = false 

Constructor that just initialises this object (esp.

opening the packet log file), but it does not start a listener thread.

peer_count: The maximum number of peers.
channel_limit: The maximum number of channels per peer.
max_incoming_bandwidth: The maximum incoming bandwidth.
max_outgoing_bandwidth: The maximum outgoing bandwidth.
change_port_if_bound: Use another port if the prefered port is already bound to a socket.

◆ ~Network()

Network::~Network ( )


Stops the listening thread, closes the packet log file and destroys the enet host.

Member Function Documentation

◆ broadcastPacket()

void Network::broadcastPacket ( NetworkString data,
bool  reliable = true 

Broadcasts a packet to all peers.

data: Data to send.

◆ getENetHost()

ENetHost* Network::getENetHost ( )

Returns a pointer to the ENet host object.

◆ logPacket()

void Network::logPacket ( const BareNetworkString ns,
bool  incoming 

Log packets into a file.

ns: The data in the packet
incoming: True if the packet comes from a peer. False if it's sent to a peer.

◆ receiveRawPacket()

int Network::receiveRawPacket ( char *  buffer,
int  buf_len,
SocketAddress sender,
int  max_tries = -1 

Receives a packet directly from the network interface and filter its address.

Receive a packet whithout ENet processing it. Checks that the sender of the packet is the one that corresponds to the sender parameter. Does not check the port right now.

bufferA buffer to receive the data in.
buf_lenLength of the buffer.
[out]sender: Transport address of the original sender of the wanted packet. If the ip address is 0, do not check the sender's ip address, otherwise wait till a message from the specified sender arrives. All other messages are discarded.
max_tries: Number of times we try to read data from the socket. This is aproximately the time we wait in milliseconds. -1 means eternal tries.
Length of the received data, or -1 if no data was received.

◆ sendRawPacket()

void Network::sendRawPacket ( const BareNetworkString buffer,
const SocketAddress dst 

Sends a packet whithout ENet adding its headers.

This function is used in particular to achieve the STUN protocol.

data: Data to send.
dst: Destination of the packet.

Member Data Documentation

◆ m_host

ENetHost* Network::m_host

ENet host interfacing sockets.

◆ m_log_file

Synchronised< FILE * > Network::m_log_file

Where to log packets.

If NULL for FILE* logging is disabled.

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