This page has been translated automatically.
UnigineScript
The Language
Core Library
Engine Library
Node-Related Classes
GUI-Related Classes
Plugins Library
High-Level Systems
Samples
C++ API
API Reference
Integration Samples
Usage Examples
Content Creation
Materials
Unigine Material Library
Tutorials
Warning! This version of documentation is OUTDATED, as it describes an older SDK version! Please switch to the documentation for the latest SDK version.
Warning! This version of documentation describes an old SDK version which is no longer supported! Please upgrade to the latest SDK version.

LAN Server Discovery

LAN Server Discovery

LAn server discovery is teh easiest way to organize a game over a network.

  1. First of all, a port needs to be set for a server to listen on for incoming connections.
  2. To discover game servers, a client sends out a broadcast message (ID_PING) over a local network.
  3. After receiving this message, a server that is currently running sends the response (ID_PONG) back to the client if it matches the filter. As a filter (game_type_info) a game version is usually used.
  4. A server can send additional information in its ID_PONG message (for example, it can be a map name or the current number of players).

Moreover:

The following events are used to handle network messages for LAN server discovery:

LAN Server Discovery / Offline Ping Functions

  • int network.pingAvailableLANServers(int listen_port,int server_port,string game_type_info) — sends a request to discover servers in the LAN.
    • listen_port — the number of a port used by the client to receive response from servers
    • server_port — the number of a port to direct request to (i.e. a broadcast request will be sent to the specified port)
    • game_type_info — string containing game information. It used to filter out server responses (in order to receive responses only from necessary servers).
      This function returns 1 if the request was successfully sent; otherwise, 0.
  • int network.advertiseServer(int listen_port) — sends information about the server into the LAN.
    • listen_port — the number of a port to direct packets to
      This function returns 1 if the request was successfully sent; otherwise, 0.
  • int network.ping(NetworkAddress network_address) — sends off-line ping to the specified address. (It is used to send ping to network node when no connection is established).
    • network_address — address of the target network node
      This function returns 1 if the request was successfully sent; otherwise, 0.
  • void network.setGameTypeInfo(string game_type_info) — sets information about the game. By this information clients will find necessary servers in the LAN and filter out all the rest.
    • game_type_info — string containing game information.
  • string network.getGameTypeInfo() — gets a string that contains information about the game and is used to filter out responses from servers in the LAN.
  • void network.setCustomInfo(string custom_info) — sets additional information that will be sent in response to a server discovery request or to an offline ping one.
  • string network.getCustomInfo() — gets additional information that will be sent in response to the server discovery request or to an offline ping one.

Samples

  • Example of server discovery can be found under <UnigineSDK>/data/network/samples/land_discovery folder.
  • Example of restoring connection and changing to another server can be found under <UnigineSDK>/data/network/samples/server_reelection folder.
Last update: 2017-07-03
Build: ()