Provides the application an interface for both client and server networking. More...
#include <Network.h>

Public Member Functions | |
| NetworkServer * | StartServer (unsigned short port, SocketTransportLayer transport, INetworkServerListener *serverListener, bool allowAddressReuse) |
| Starts a network server that listens to the given local port. | |
| NetworkServer * | StartServer (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 () |
| Socket * | ConnectSocket (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. | |
Provides the application an interface for both client and server networking.
| NetworkServer * kNet::Network::StartServer | ( | unsigned short | port, | |
| SocketTransportLayer | transport, | |||
| INetworkServerListener * | serverListener, | |||
| bool | allowAddressReuse | |||
| ) |
Starts a network server that listens to the given local port.
| 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.
| 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 | ( | ) |
| 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.
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.
1.7.1