Classes | Typedefs | Enumerations | Enumerator | Functions | Variables

Networking API
[Networking Libraries]

This is a very basic networking API layer. More...

Collaboration diagram for Networking API:

Classes

class  netlib::MessageBuffer
struct  netlib::connection_info_t
struct  netlib::envelope_t
 An envelope describes from where and how a remote message arrived. More...

Typedefs

typedef dword_t netlib::conn_id_t
 connection ID type. Will never be null for a valid connection.

Enumerations

enum  netlib::eConnectionType {
  netlib::eType_TCP = 0x0001,
  netlib::eType_SecureTCP = 0x0002,
  netlib::eType_UDPLocal = 0x0010,
  netlib::eType_UDPRemote = 0x0020,
  netlib::eType_UDPBroadcast = 0x0040,
  netlib::eType_TCPListener = 0x0100,
  netlib::eType_Invalid = 0
}
 

the type of connection

More...

Functions

void netlib::connection_info_t::clear (void) throw ()
bool netlib::connection_info_t::is_valid (void) const throw ()
void netlib::connection_info_t::dump (const char *title) const throw ()
void netlib::envelope_t::clear (void) throw ()
bool netlib::envelope_t::is_empty (void) const throw ()
bool netlib::envelope_t::isValid (void) const throw ()
std::string netlib::getServerFromIP (const ip_addr_t &ip)
conn_id_t netlib::createTcpListener (const address_t &address,int maxBacklog)
 create a listener (if clients connect, you'll see their messages show up)
conn_id_t netlib::createTcpConnection (const address_t &address)
 create a connection to a remote peer (connection ID is returned)
conn_id_t netlib::createUdpLocal (const address_t &localUdp)
 create a local UDP connection for sending/receiving datagrams.
conn_id_t netlib::createUdpRemote (conn_id_t localUdp,const address_t &address)
 create a logical connection to represent a remote UDP sender/receiver

  • caller must specify the local UDP connection that will communicate this is used for sending to remote UDP listeners

conn_id_t netlib::createUdpBroadcast (const address_t &broadcastAddress)
 create a local UDP sending point for datagram broadcasts to a specific port.
bool netlib::enqueueMessage (conn_id_t connId,smart_ptr< MessageBuffer > &message)
 asynchronously send data to a particular connection

  • conn_id specifies the (remote) receiver
  • queued messages are actually sent via getNextMessage() calls

bool netlib::getNextMessage (long wait_microseconds,netlib::envelope_t &envelope,smart_ptr< MessageBuffer > &buffer)
 get next message from all open connections (empty if no messages waiting)

  • this is the main message pump so applications should keep calling it

bool netlib::isValidConnection (conn_id_t conn_id)
 is this a valid connection?
bool netlib::getConnectionInfo (conn_id_t conn_id,connection_info_t &info)
 given a connection, retrieve information about it
void netlib::closeConnection (conn_id_t conn_id)
 terminate a particular connection
void netlib::dumpMessage (std::ostream &stream,const char *title,const envelope_t &envelope,const MessageBuffer *buffer)
 for debugging
void netlib::dumpStats (void)
 info only

Variables

eConnectionType netlib::connection_info_t::type
address_t netlib::connection_info_t::address
int netlib::connection_info_t::port
conn_id_t netlib::envelope_t::fromConnId
eConnectionType netlib::envelope_t::type
 source connection ID
address_t netlib::envelope_t::address

Detailed Description

This is a very basic networking API layer.

You can create connections (using the various constructors) and get back a connection ID. Then you can read/write to the connection based on the ID.

You can write to the connection any time using the connection ID.

The getNextMessage() API is the core message pump. The application should repeatedly call this so that messages get sent in and out.

WARNING: this library is NOT threadsafe! You should handle any synchronization issues at a higher layer.


Typedef Documentation

connection ID type. Will never be null for a valid connection.

Definition at line 71 of file netlib.h.


Enumeration Type Documentation

the type of connection

Enumerator:
eType_TCP 

standard tcp/ip connection

eType_SecureTCP 

ssl connection

eType_UDPLocal 

can send/receive UDP datagrams

eType_UDPRemote 

our record of remote UDP socket

eType_UDPBroadcast 

can broadcast UDP datagrams

eType_TCPListener 

local tcp listening socket

eType_Invalid 

Definition at line 75 of file netlib.h.


Function Documentation

void netlib::connection_info_t::clear ( void   )  throw () [inline, inherited]

Definition at line 94 of file netlib.h.

bool netlib::connection_info_t::is_valid ( void   )  const throw () [inline, inherited]

Definition at line 99 of file netlib.h.

void netlib::connection_info_t::dump ( const char *  title  )  const throw () [inherited]

Definition at line 1201 of file netlib.cpp.

void netlib::envelope_t::clear ( void   )  throw () [inline, inherited]

Definition at line 116 of file netlib.h.

bool netlib::envelope_t::is_empty ( void   )  const throw () [inline, inherited]

Definition at line 121 of file netlib.h.

bool netlib::envelope_t::isValid ( void   )  const throw () [inline, inherited]

Definition at line 124 of file netlib.h.

std::string netlib::getServerFromIP ( const ip_addr_t &  ip  ) 

return the hostname (or IP in string form!)

conn_id_t netlib::createTcpListener ( const address_t &  address,
int  maxBacklog 
)

create a listener (if clients connect, you'll see their messages show up)

conn_id_t netlib::createTcpConnection ( const address_t &  address  ) 

create a connection to a remote peer (connection ID is returned)

conn_id_t netlib::createUdpLocal ( const address_t &  localUdp  ) 

create a local UDP connection for sending/receiving datagrams.

This connection will receive datagrams sent to this local port from any remote location (including broadcast packets). You have to specify the full local address. This is important for machines with multiple interfaces, and even for a machine with a single interface, you need to specify the physical interface vs. a local host loopback (127.0.0.1). To send UDP datagrams from this connection, create a remote UDP connection using createUdpRemote() and use this connection as the localUdp connection. To broadcast UDP datagrams, you won't use this connection at all. Instead, create a broadcast UDP datagram connection using createUdpBroadcast().

conn_id_t netlib::createUdpRemote ( conn_id_t  localUdp,
const address_t &  address 
)

create a logical connection to represent a remote UDP sender/receiver

  • caller must specify the local UDP connection that will communicate this is used for sending to remote UDP listeners

conn_id_t netlib::createUdpBroadcast ( const address_t &  broadcastAddress  ) 

create a local UDP sending point for datagram broadcasts to a specific port.

Caller must specify the broadcast address, such as 192.168.0.255

bool netlib::enqueueMessage ( conn_id_t  conn_id,
smart_ptr< MessageBuffer > &  message 
)

asynchronously send data to a particular connection

  • conn_id specifies the (remote) receiver
  • queued messages are actually sent via getNextMessage() calls

bool netlib::getNextMessage ( long  wait_microseconds,
envelope_t &  envelope,
smart_ptr< MessageBuffer > &  msgbuf 
)

get next message from all open connections (empty if no messages waiting)

  • this is the main message pump so applications should keep calling it

bool netlib::isValidConnection ( conn_id_t  conn_id  ) 

is this a valid connection?

bool netlib::getConnectionInfo ( conn_id_t  conn_id,
connection_info_t &  info 
)

given a connection, retrieve information about it

void netlib::closeConnection ( conn_id_t  conn_id  ) 

terminate a particular connection

void netlib::dumpMessage ( std::ostream &  stream,
const char *  title,
const envelope_t &  envelope,
const MessageBuffer *  buffer 
)

for debugging

void netlib::dumpStats ( void   ) 

info only


Variable Documentation

eConnectionType netlib::connection_info_t::type [inherited]

Definition at line 105 of file netlib.h.

address_t netlib::connection_info_t::address [inherited]

Definition at line 106 of file netlib.h.

Definition at line 107 of file netlib.h.

conn_id_t netlib::envelope_t::fromConnId [inherited]

Definition at line 133 of file netlib.h.

eConnectionType netlib::envelope_t::type [inherited]

source connection ID

Definition at line 134 of file netlib.h.

address_t netlib::envelope_t::address [inherited]

Definition at line 135 of file netlib.h.