Public Member Functions | Static Public Member Functions

kNet::Network Class Reference

Provides the application an interface for both client and server networking. More...

#include <Network.h>

Collaboration diagram for kNet::Network:
Collaboration graph
[legend]

List of all members.

Public Member Functions

NetworkServerStartServer (unsigned short port, SocketTransportLayer transport, INetworkServerListener *serverListener, bool allowAddressReuse)
 Starts a network server that listens to the given local port.
NetworkServerStartServer (const std::vector< std::pair< unsigned short, SocketTransportLayer > > &listenPorts, INetworkServerListener *serverListener, bool allowAddressReuse)
 Starts a network server that listens to multiple local ports.
void StopServer ()
SocketConnectSocket (const char *address, unsigned short port, SocketTransportLayer transport)
 Connects a raw socket (low-level, no MessageConnection abstraction) to the given destination.
void CloseSocket (Socket *socket)
 Closes (==frees) the given Socket object.
 Ptr (MessageConnection) Connect(const char *address
 Connects to the given address:port using kNet over UDP or TCP.
const char * LocalAddress () const
 Returns the local host name of the system (the local machine name or the local IP, whatever is specified by the system).
void AssignConnectionToWorkerThread (Ptr(MessageConnection) connection)
 Takes the given MessageConnection and associates a NetworkWorkerThread for it.
int NumWorkerThreads () const
 Returns the amount of currently executing background network worker threads.

Static Public Member Functions

static std::string GetErrorString (int error)
 Returns the error string associated with the given networking error id.
static std::string GetLastErrorString ()
 Returns the error string corresponding to the last error that occurred in the networking library.
static int GetLastError ()
 Returns the error id corresponding to the last error that occurred in the networking library.

Detailed Description

Provides the application an interface for both client and server networking.


Member Function Documentation

NetworkServer * kNet::Network::StartServer ( unsigned short  port,
SocketTransportLayer  transport,
INetworkServerListener serverListener,
bool  allowAddressReuse 
)

Starts a network server that listens to the given local port.

Parameters:
serverListener [in] A pointer to the listener object that will be registered to receive notifications about incoming connections.
allowAddressReuse If true, kNet passes the SO_REUSEADDR parameter to the server listen socket before binding the socket to a local port (== before starting the server). This allows the same port to be forcibly reused when restarting the server if a crash occurs, without having to wait for the operating system to free up the port.

References LOG, and kNet::Socket::ToString().

NetworkServer * kNet::Network::StartServer ( const std::vector< std::pair< unsigned short, SocketTransportLayer > > &  listenPorts,
INetworkServerListener serverListener,
bool  allowAddressReuse 
)

Starts a network server that listens to multiple local ports.

This version of the function is given a list of pairs (port, UDP|TCP) values and the server will start listening on each of them.

Parameters:
allowAddressReuse If true, kNet passes the SO_REUSEADDR parameter to the server listen socket before binding the socket to a local port (== before starting the server). This allows the same port to be forcibly reused when restarting the server if a crash occurs, without having to wait for the operating system to free up the port.

References LOG.

void kNet::Network::StopServer (  ) 

Todo:
This is a forceful stop. Perhaps have a benign teardown as well?

References LOG.

Socket * kNet::Network::ConnectSocket ( const char *  address,
unsigned short  port,
SocketTransportLayer  transport 
)

Connects a raw socket (low-level, no MessageConnection abstraction) to the given destination.

Todo:
Check return value.
Todo:
Check return value.

References kNet::EndPoint::FromSockAddrIn(), GetErrorString(), GetLastError(), kNet::EndPoint::IPToString(), and LOG.

void kNet::Network::CloseSocket ( Socket socket  ) 

Closes (==frees) the given Socket object.

After calling this function, do not dereference that Socket pointer, as it is deleted.

References kNet::Socket::Close(), and LOG.

Referenced by kNet::NetworkServer::ConnectionClosed().

kNet::Network::Ptr ( MessageConnection   )  const

Connects to the given address:port using kNet over UDP or TCP.

When you are done with the connection, free it by letting the refcount go to 0.


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