Example #1
0
 protected override void OnUpdate()
 {
     // Destroy singleton to prevent system from running again
     EntityManager.DestroyEntity(GetSingletonEntity <InitGameComponent>());
     foreach (World world in World.All)
     {
         NetworkStreamReceiveSystem network = world.GetExistingSystem <NetworkStreamReceiveSystem>();
         if (world.GetExistingSystem <ClientSimulationSystemGroup>() != null)
         {
             // Client worlds automatically connect to localhost
             NetworkEndPoint ep = NetworkEndPoint.LoopbackIpv4;
             ep.Port = 7979;
             network.Connect(ep);
         }
         #if UNITY_EDITOR
         else if (world.GetExistingSystem <ServerSimulationSystemGroup>() != null)
         {
             // Server world automatically listens for connections from any host
             NetworkEndPoint ep = NetworkEndPoint.AnyIpv4;
             ep.Port = 7979;
             network.Listen(ep);
         }
         #endif
     }
 }
Example #2
0
        private bool ConnectToServer(NetworkStreamReceiveSystem network, string address, ushort port)
        {
            NetworkEndPoint ep         = NetworkEndPoint.Parse(address, port);
            var             connection = network.Connect(ep);

            Debug.Log($"ConnectToServer({ep.Address}) => {connection}");

            return(connection != Entity.Null);
        }
Example #3
0
        protected override void OnUpdate()
        {
            EntityManager.DestroyEntity(GetSingletonEntity <Connect>());
            NetworkStreamReceiveSystem network = World.GetExistingSystem <NetworkStreamReceiveSystem>();

            if (network == null || World.GetExistingSystem <ClientSimulationSystemGroup>() == null)
            {
                return;
            }

            NetworkEndPoint ep = NetworkEndPoint.LoopbackIpv4;

            ep.Port = 21650;
            network.Connect(ep);
            Debug.Log("Connecting to LobbyWorld...");
        }