Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Host

Overview

The basic task of these classes is the interface between Orxonox and the network engine. This includes creating and opening a server, connecting to a server as client and provide common functions (for Server and Client) like sendChat.

Host is the parent class of Server and Client. It ensures that only one instance of either Server or Client is running (so called Singleton) and provides static functions that both (Server and Client) have to implement.

Host class and common functions

Below is a list of functions that you might want to use:

Function Name Description
running() Tells you whether an instance of Server or Client exists (no Information, wheter connected or not)
isServer() Tells you whether the instance is a Server or not
sendChat(message) Sends a message to the server or the clients

Server class

Obviously this class implements a server. See below for usage.
Special functions of Server (not included in Host):

Function Name Description
Server() Constructor: sets port to 55556 and binds to all addresses
Server(int portnr) Constructor: sets port to portnr
Server(int portnr, string bindaddress) Constructor: sets port to portnr and listens to bindaddress
open() opens the listener and accepts new connections
close() closes the listener

Client class

Special functions of Client (not included in Host):

Function Name Description
Client() Constructor: sets destination address and port to localhost|55556
Client(string address, int port) Constructor with user defined destination address and port
establishConnection() tries to connect to the server
closeConnection() closes the connection

ClientInformation

This class implements a list with all neccessary information about a client (e.g. network address, port, PlayerID, shipID, gamestateID, …). It is used by Server and designed for internal use only.

Usage Examples

Server usage:

network::Server server(); // this creates the server and sets port and bindaddress to the default values
server.open();

Client usage:

network::Client client(address, port); // this creates the client and sets port and dest.address to appropriate values
if(client.establishConnection())
  ... //success
else
  ... //failure
Last modified 7 years ago Last modified on Apr 12, 2017, 11:39:03 PM