Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes

sp::network::NetworkSystem Class Reference
[Network System]

#include <spNetworkSystem.hpp>

Inheritance diagram for sp::network::NetworkSystem:
sp::network::NetworkSystemTCP sp::network::NetworkSystemUDP

List of all members.

Public Member Functions

virtual ~NetworkSystem ()
virtual io::stringc getVersion () const
 Returns the network system version.
virtual io::stringc getDescription () const =0
 Returns a description string for the network system.
virtual NetworkServerhostServer (u16 Port=DEFAULT_PORT)=0
 Hosts a new network server.
virtual NetworkServerjoinServer (const io::stringc &IPAddress, u16 Port=DEFAULT_PORT)=0
 Joins the network server.
virtual void disconnect ()=0
 Disconnects from the current network server and closes the network session.
virtual bool sendPacket (const NetworkPacket &Packet, NetworkMember *Receiver=0)=0
virtual bool receivePacket (NetworkPacket &Packet, NetworkMember *&Sender)=0
void processPackets ()
bool waitForConnection ()
virtual bool popClientJoinStack (NetworkClient *&Client)=0
virtual bool popClientLeaveStack (NetworkClient *&Client)=0
virtual NetworkMembergetMemberByAddress (const NetworkAddress &Address)=0
NetworkServergetServer () const
 Returns pointer to the NetworkServer object.
const std::list< NetworkClient * > & getClientList () const
 Returns the whole client object list.
bool isSessionRunning () const
 Returns true if a network session is currently running, i.e. a server has been opened or joined.
bool isConnected () const
 Returns true if a network session is currently connected, i.e. a server has been opened or an external joined server has accepted the connection.
bool isServer () const
 Returns true if a network server was opened by this computer (in this case this network system is the server).

Static Public Member Functions

static io::stringc getHostIPAddress (const io::stringc &HostName)
static io::stringc getOfficialHostName (const io::stringc &HostName)
 Returns the official host name (e.g. "www.google.com" to "www.l.google.com").
static std::list< io::stringcgetHostIPAddressList (const io::stringc &HostName)
static std::list< io::stringcgetNetworkMembers ()
static std::list< SNetworkAdaptergetNetworkAdapters ()
 Returns all network adapters on the local computer.
static std::list< io::stringcgetBroadcastIPList ()

Protected Member Functions

 NetworkSystem ()
void createWinSock ()
void deleteWinSock ()
void registerMember (NetworkMember *Member)
NetworkMembergetMemberByAddress (const sockaddr_in &SenderAddr)
NetworkClientcreateClient (const NetworkAddress &ClientAddr)
void deleteClient (NetworkClient *Client)
void closeNetworkSession ()

Protected Attributes

WSADATA WinSock_
NetworkServerServer_
std::list< NetworkClient * > ClientList_
std::list< NetworkClient * > ClientJointStack_
std::list< NetworkClient * > ClientLeaveStack_
std::map< u64, NetworkMember * > MemberMap_
bool isSessionRunning_
bool isConnected_
bool hasOpenedServer_

Detailed Description

Use this class for your network system interface.


Constructor & Destructor Documentation

virtual sp::network::NetworkSystem::~NetworkSystem (  )  [virtual]
sp::network::NetworkSystem::NetworkSystem (  )  [protected]

Member Function Documentation

void sp::network::NetworkSystem::closeNetworkSession (  )  [protected]
NetworkClient* sp::network::NetworkSystem::createClient ( const NetworkAddress ClientAddr  )  [protected]
void sp::network::NetworkSystem::createWinSock (  )  [protected]
void sp::network::NetworkSystem::deleteClient ( NetworkClient Client  )  [protected]
void sp::network::NetworkSystem::deleteWinSock (  )  [protected]
virtual void sp::network::NetworkSystem::disconnect (  )  [pure virtual]

Disconnects from the current network server and closes the network session.

Implemented in sp::network::NetworkSystemTCP, and sp::network::NetworkSystemUDP.

static std::list<io::stringc> sp::network::NetworkSystem::getBroadcastIPList (  )  [static]

Returns a unique list of all available broadcast IP addresses. This depends on the count of network adapters.

See also:
getNetworkAdapters
const std::list<NetworkClient*>& sp::network::NetworkSystem::getClientList (  )  const [inline]

Returns the whole client object list.

virtual io::stringc sp::network::NetworkSystem::getDescription (  )  const [pure virtual]

Returns a description string for the network system.

Implemented in sp::network::NetworkSystemTCP, and sp::network::NetworkSystemUDP.

static io::stringc sp::network::NetworkSystem::getHostIPAddress ( const io::stringc HostName  )  [static]

Returns the IP address of the specified host name.

Parameters:
HostName,: Specifies the host name (or rather local PC name).
static std::list<io::stringc> sp::network::NetworkSystem::getHostIPAddressList ( const io::stringc HostName  )  [static]

Gets all IP addresses of the specified host name.

Parameters:
HostName,: Specifies the host name (or rather local PC name):
Returns:
List of all IP addresses.
virtual NetworkMember* sp::network::NetworkSystem::getMemberByAddress ( const NetworkAddress Address  )  [pure virtual]

Returns a pointer to the network member with the given address or 0 (null) if there is no member with this address.

Implemented in sp::network::NetworkSystemTCP, and sp::network::NetworkSystemUDP.

NetworkMember* sp::network::NetworkSystem::getMemberByAddress ( const sockaddr_in &  SenderAddr  )  [protected]
static std::list<SNetworkAdapter> sp::network::NetworkSystem::getNetworkAdapters (  )  [static]

Returns all network adapters on the local computer.

static std::list<io::stringc> sp::network::NetworkSystem::getNetworkMembers (  )  [static]

Gets all network member host names (or rather local PC names).

Returns:
List of all host names.
Note:
This function sometimes needs a couple of seconds and currently is only supported for MS/Windows.
static io::stringc sp::network::NetworkSystem::getOfficialHostName ( const io::stringc HostName  )  [static]

Returns the official host name (e.g. "www.google.com" to "www.l.google.com").

NetworkServer* sp::network::NetworkSystem::getServer (  )  const [inline]

Returns pointer to the NetworkServer object.

virtual io::stringc sp::network::NetworkSystem::getVersion (  )  const [virtual]

Returns the network system version.

virtual NetworkServer* sp::network::NetworkSystem::hostServer ( u16  Port = DEFAULT_PORT  )  [pure virtual]

Hosts a new network server.

Implemented in sp::network::NetworkSystemTCP, and sp::network::NetworkSystemUDP.

bool sp::network::NetworkSystem::isConnected (  )  const [inline]

Returns true if a network session is currently connected, i.e. a server has been opened or an external joined server has accepted the connection.

bool sp::network::NetworkSystem::isServer (  )  const [inline]

Returns true if a network server was opened by this computer (in this case this network system is the server).

bool sp::network::NetworkSystem::isSessionRunning (  )  const [inline]

Returns true if a network session is currently running, i.e. a server has been opened or joined.

virtual NetworkServer* sp::network::NetworkSystem::joinServer ( const io::stringc IPAddress,
u16  Port = DEFAULT_PORT 
) [pure virtual]

Joins the network server.

Implemented in sp::network::NetworkSystemTCP, and sp::network::NetworkSystemUDP.

virtual bool sp::network::NetworkSystem::popClientJoinStack ( NetworkClient *&  Client  )  [pure virtual]

Pops a client from the join-stack. Use this to determine when a new client joined the server.

Parameters:
Client,: Specifies where the client pointer is to be stored.
Returns:
True if a new client has joined the server.
        // Example:
        NetworkClient* NewClient;
        while (spNetwork->popClientJoinStack(NewClient))
            AddNewClientToGame(NewClient);

Implemented in sp::network::NetworkSystemTCP, and sp::network::NetworkSystemUDP.

virtual bool sp::network::NetworkSystem::popClientLeaveStack ( NetworkClient *&  Client  )  [pure virtual]

Pops a client from the leave-stack. Use this to determine when a client left the server.

Parameters:
Client,: Specifies where the client pointer is to be stored.
Returns:
True if a client has left the server.
        // Example:
        NetworkClient* LeftClient;
        while (spNetwork->popClientLeaveStack(LeftClient))
            RemoveOldClientFromGame(LeftClient);
Note:
Here you only have to use the pointer for comparision but no longer use the object, because it has already been deleted!

Implemented in sp::network::NetworkSystemTCP, and sp::network::NetworkSystemUDP.

void sp::network::NetworkSystem::processPackets (  ) 

Processes each incomming network packet only for internal purposes. This is equivalent to the following code snippet:

        NetworkPacket Packet;
        NetworkMember* Sender = 0;
        while (spNetwork->receivePacket(Packet, Sender));
virtual bool sp::network::NetworkSystem::receivePacket ( NetworkPacket Packet,
NetworkMember *&  Sender 
) [pure virtual]

Receives a network packet and returns the sender.

Parameters:
Packet,: Returns a new incomming message.
Sender,: Returns the sender.
Returns:
True if a new network packet has been received.

Implemented in sp::network::NetworkSystemTCP, and sp::network::NetworkSystemUDP.

void sp::network::NetworkSystem::registerMember ( NetworkMember Member  )  [protected]
virtual bool sp::network::NetworkSystem::sendPacket ( const NetworkPacket Packet,
NetworkMember Receiver = 0 
) [pure virtual]

Sends a network packet to the given network member.

Parameters:
Packet,: Specifies the network packet which is to be send.
Receiver,: Specifies the network member which is to receive the packet. By default 0 which means that each member gets the packet.
Returns:
True if the function succeeded.

Implemented in sp::network::NetworkSystemTCP, and sp::network::NetworkSystemUDP.

bool sp::network::NetworkSystem::waitForConnection (  ) 

Processes each incomming netowrk packet and retuns true once the server accepted the connection. Use this as a UDP client after joining a server.


Member Data Documentation


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