Class NetworkManager


  • public class NetworkManager
    extends Object
    Class that manaes network stuff
    Author:
    Darius Dinger
    • Constructor Detail

      • NetworkManager

        public NetworkManager()
    • Method Detail

      • host

        public static boolean host​(int port,
                                   int maxPlayers,
                                   String password,
                                   Class<? extends PlayerGameObject> playerClass)
        Setting up a dedicated server
        Parameters:
        port - Port to bind the server to
        maxPlayers - Max players to join
        password - Password of the server
        playerClass - Class to instance when players join
        Returns:
        Could the server be created
      • join

        public static TCPClient.HandshakeResult join​(String ip,
                                                     int port,
                                                     String password,
                                                     String name,
                                                     Class<? extends PlayerGameObject> playerClass)
        Joining a running server.
        Parameters:
        ip - Ip address of the server
        port - Port of the server
        password - Password of the server
        name - Player name on the server
        playerClass - Class to instance when players join
        Returns:
        Joining handshake result
      • hostAndJoin

        public static boolean hostAndJoin​(int port,
                                          int maxPlayers,
                                          String password,
                                          String name,
                                          Class<? extends PlayerGameObject> playerClass)
        Hosting and joining a server via localhost
        Parameters:
        port - Port to bind the server to
        maxPlayers - Max players for te server
        password - Password of the server
        playerClass - Class to instance when players join
        name - Player name on the server
        Returns:
        Could the server be created
      • stop

        public static void stop​(String message)
        Stops every connection
        Parameters:
        message - Message to send to connections before closing
      • sync

        public static void sync()
        Updating the network manager