コード例 #1
0
    public virtual void Start()
    {
        //RESETS OUT DATA
        m_Driver = NetworkDriver.Create();

        //CONFIGURATION
        NetworkEndPoint endpoint = NetworkEndPoint.AnyIpv4;

        endpoint.Port = 9000;

        //BIND THE NET DRIVER
        if (m_Driver.Bind(endpoint) != 0)
        {
            Debug.Log(LogPrefix + "Faileld to bind port 9000");
        }
        else
        {
            //start listening
            m_Driver.Listen();
        }

        //init the list to hold out connections
        m_Connections = new NativeList <NetworkConnection>(16, Allocator.Persistent);

        RegisterMessageHandlerClasses();
    }
コード例 #2
0
    void Start()
    {
        lastTimeSendAllPlayerInfo        = Time.time;
        intervalTimeSendingAllPlayerInfo = 0.03f;


        // Driver -> like socket
        m_Driver = NetworkDriver.Create();

        // 어디에 연결할지, AnyIpv4--> 머신이 돌아가는 위치의 IP
        // -> where to connect. AnyIpv4 is the location of machine's ip
        var endpoint = NetworkEndPoint.AnyIpv4;

        // Port setting
        endpoint.Port = serverPort;

        // Bind the socket
        if (m_Driver.Bind(endpoint) != 0)
        {
            Debug.Log("Failed to bind to port " + serverPort);
        }

        //if bind is good, server is ready to accept clients' connections
        else
        {
            m_Driver.Listen();
        }

        //커넥션 - 서버가 클라들의 접속을 알수있게(관리함) 해주는 다리, NativeList--> List와 비슷
        // -> m_Connections is like bridges that server knows which clients want to connect to the server. NativeList is a List
        m_Connections = new NativeList <NetworkConnection>(16, Allocator.Persistent);
    }
コード例 #3
0
ファイル: Host.cs プロジェクト: tycobbb/zerocompany
    // -- lifecycle --
    private void Start()
    {
        mDriver = NetworkDriver.Create(new NetworkConfigParameter()
        {
            disconnectTimeoutMS = int.MaxValue,
        });

        var endpoint = NetworkEndPoint.AnyIpv4;

        endpoint.Port = Config.kPort;

        var res = mDriver.Bind(endpoint);

        if (res != 0)
        {
            Log.E($"Host - failed to listen on port {Config.kPort} (err: {res})");
        }
        else
        {
            mDriver.Listen();
            Log.I($"Host - listen on {Config.kPort}");
        }

        mConnections = new NativeList <NetworkConnection>(kMaxConnections, Allocator.Persistent);
    }
コード例 #4
0
    void Start()
    {
        networkDriver = NetworkDriver.Create();

        NetworkEndPoint endpoint = NetworkEndPoint.AnyIpv4;

        endpoint.Port = 9000;

        if (!GameManager.Instance.LOCAL)
        {
            endpoint = NetworkEndPoint.Parse(IPAdress, 9000);
        }

        if (networkDriver.Bind(endpoint) != 0)
        {
            Debug.Log("Failed to bind port");
        }
        else
        {
            networkDriver.Listen();
        }

        connections = new NativeList <NetworkConnection>(16, Allocator.Persistent);

        serverMessagesQueue = new Queue <MessageHeader>();

        for (int i = 0; i < ServerCallbacks.Length; i++)
        {
            ServerCallbacks[i] = new MessageEvent();
        }
        ServerCallbacks[(int)MessageHeader.MessageType.SetName].AddListener(HandleSetName);
        ServerCallbacks[(int)MessageHeader.MessageType.PlayerLeft].AddListener(DisconnectClient);
    }
コード例 #5
0
        //#endif


        public virtual void Init()
        {
            updateTimer = 1 / TICKS_PER_SECONDS;
            lastUpdate  = Time.time;

            driver = NetworkDriver.Create();
            NetworkEndPoint endPoint = NetworkEndPoint.AnyIpv4;     // Allow anybody to connect to us

            endPoint.Port = PORT;

            netMessageHandlerManager = new NetMessageHandlerManager(this);
            messageSender            = new MessageSender(this);
            entityManager            = new EntityManager();
            players = new Dictionary <int, NetworkConnection>();

            if (driver.Bind(endPoint) != 0)
            {
                Logs.Error($"Error while binding to {PORT}");
                Shutdown();
            }
            else
            {
                driver.Listen();
                Logs.Print($"Server running at port {PORT} with {TICKS_PER_SECONDS} ticks/s");
            }

            connections = new NativeList <NetworkConnection>(MAX_CLIENTS, Allocator.Persistent);
        }
コード例 #6
0
    public void Start()
    {
        networkDriver = NetworkDriver.Create();
        var endpoint = NetworkEndPoint.AnyIpv4;

        endpoint.Port = 9000;
        if (networkDriver.Bind(endpoint) != 0)
        {
            Debug.Log("Failed to bind port");
        }
        else
        {
            networkDriver.Listen();
        }

        connections = new NativeList <NetworkConnection>(16, Allocator.Persistent);

        receivedMessagesQueue = new Queue <AdressedMessage>();
        sendMessagesQueue     = new Queue <AdressedMessage>();

        //assign all eventlisteners
        for (int i = 0; i < ServerCallbacks.Length; i++)
        {
            ServerCallbacks[i] = new AdressedMessageEvent();
        }
        ServerCallbacks[(int)Message.MessageType.SetName].AddListener(serverManager.HandleSetName);
        ServerCallbacks[(int)Message.MessageType.MoveRequest].AddListener(serverManager.HandleMoveRequest);
        ServerCallbacks[(int)Message.MessageType.AttackRequest].AddListener(serverManager.HandleAttackRequest);
        ServerCallbacks[(int)Message.MessageType.DefendRequest].AddListener(serverManager.HandleDefendRequest);
        ServerCallbacks[(int)Message.MessageType.ClaimTreasureRequest].AddListener(serverManager.HandleClaimTreasureRequest);
        ServerCallbacks[(int)Message.MessageType.LeaveDungeonRequest].AddListener(serverManager.HandleLeaveDungeonRequest);

        Debug.Log("Host Started");
    }
コード例 #7
0
        void Start()
        {
            m_Connections             = new NativeList <NetworkConnection>(16, Allocator.Persistent);
            m_Room                    = new NativeList <Room>(16, Allocator.Persistent);
            m_ConnectedClients        = new NativeMultiHashMap <int, Client>(16, Allocator.Persistent);
            m_ConnectionIndexToRoomID = new NativeHashMap <int, int>(1, Allocator.Persistent);
            m_ServerAddressToRoomID   = new NativeHashMap <FixedString32, int>(1, Allocator.Persistent);
            m_ReleasedRoomIds         = new NativeList <Room>(Allocator.Persistent);

            // Driver can be used as normal
            m_Driver = NetworkDriver.Create();
            // Driver now knows about this pipeline and can explicitly be asked to send packets through it (by default it sends directly)
            m_Pipeline = m_Driver.CreatePipeline(typeof(UnreliableSequencedPipelineStage));

            var endpoint = NetworkEndPoint.AnyIpv4;

            endpoint.Port = Config.ListenPort;
            if (m_Driver.Bind(endpoint) != 0)
            {
                Console.WriteLine($"[ERROR]Failed to bind to port {Config.ListenPort}");
            }
            else
            {
                m_Driver.Listen();
            }
        }
コード例 #8
0
        void Start()
        {
            CurrentGameState = GameState.Lobby;

            m_Driver = NetworkDriver.Create();
            var endpoint = NetworkEndPoint.AnyIpv4;

            endpoint.Port = 9000;

            if (m_Driver.Bind(endpoint) != 0)
            {
                Debug.Log("Failed to bind to port 9000");
            }
            else
            {
                m_Driver.Listen();
            }


            m_Connections = new NativeList <NetworkConnection>(16, Allocator.Persistent);

            aliveMessage = new GameObject().AddComponent <AliveMessageHandler>();
            aliveMessage.InitializeMessage(3f, false);
            aliveMessage.gameObject.name = "AliveMessage_Server";
            DontDestroyOnLoad(aliveMessage);
        }
コード例 #9
0
        public void SetupServerAndClientAndConnectThem(int bufferSize)
        {
            //setup server
            server_driver = NetworkDriver.Create(new NetworkDataStreamParameter {
                size = bufferSize
            });
            NetworkEndPoint server_endpoint = NetworkEndPoint.LoopbackIpv4;

            server_endpoint.Port = 1337;
            server_driver.Bind(server_endpoint);
            server_driver.Listen();

            //setup client
            client_driver = NetworkDriver.Create(new NetworkDataStreamParameter {
                size = bufferSize
            });
            clientToServerConnection = client_driver.Connect(server_endpoint);

            //update drivers
            client_driver.ScheduleUpdate().Complete();
            server_driver.ScheduleUpdate().Complete();

            //accept connection
            connectionToClient = server_driver.Accept();

            server_driver.ScheduleUpdate().Complete();
            ev = server_driver.PopEventForConnection(connectionToClient, out stream);
            Assert.IsTrue(ev == NetworkEvent.Type.Empty, "Not empty NetworkEvent on the server appeared");

            client_driver.ScheduleUpdate().Complete();
            ev = clientToServerConnection.PopEvent(client_driver, out stream);
            Assert.IsTrue(ev == NetworkEvent.Type.Connect, "NetworkEvent should have Type.Connect on the client");
        }
コード例 #10
0
    void Start()
    {
        networkDriver = NetworkDriver.Create();
        var endpoint = NetworkEndPoint.AnyIpv4;

        endpoint.Port = 9000;
        if (networkDriver.Bind(endpoint) != 0)
        {
            Debug.Log("Failed to bind port");
        }
        else
        {
            networkDriver.Listen();
        }

        connections = new NativeList <NetworkConnection>(16, Allocator.Persistent);

        messagesQueue = new Queue <MessageHeader>();

        for (int i = 0; i < ServerCallbacks.Length; i++)
        {
            ServerCallbacks[i] = new MessageEvent();
        }
        ServerCallbacks[(int)MessageHeader.MessageType.SetName].AddListener(HandleSetName);
    }
コード例 #11
0
    void Start()
    {   //Create driver
        m_Driver = NetworkDriver.Create();
        //Create server address
        var endpoint = NetworkEndPoint.AnyIpv4;

        endpoint.Port = serverPort;
        //If bind is not failed - listen
        if (m_Driver.Bind(endpoint) != 0)
        {
            Debug.Log("Failed to bind to port " + serverPort);
        }
        else
        {
            m_Driver.Listen();
        }

        //Create list of connections
        m_Connections = new NativeList <NetworkConnection>(16, Allocator.Persistent);
        playersIds    = new NativeList <int>(16, Allocator.Persistent);
        //Create dictionary of players ids and data
        players = new Dictionary <string, NetworkObjects.NetworkPlayer>();
        //Reset timer
        curTimeToSend = timeToSend;
    }
コード例 #12
0
ファイル: Server.cs プロジェクト: Casey-Hofland/KernmoduleIV
    public void CreateDriver(int minConnections, int maxConnections)
    {
        this.minConnections = minConnections;
        this.maxConnections = maxConnections;

        DestroyDriver();

        // Create a new driver and listen for connections.
        driver = NetworkDriver.Create(new ReliableUtility.Parameters {
            WindowSize = 32
        });
        reliablePipeline = driver.CreatePipeline(typeof(ReliableSequencedPipelineStage));

        var endPoint = NetworkEndPoint.AnyIpv4;

        endPoint.Port = 9000;

        var binding = driver.Bind(endPoint);

        Assert.AreEqual(0, binding);
        driver.Listen();

        connections    = new NativeList <NetworkConnection>(maxConnections, Allocator.Persistent);
        playerInfoByID = new NativeHashMap <int, PlayerInfo>(maxConnections, Allocator.Persistent);

        readMessage = ReadJoingingAreaMessages;
    }
コード例 #13
0
    private void Awake()
    {
        if (instance == null)
        {
            instance = this;
        }
        else
        {
            Destroy(this);
        }

        m_Driver = NetworkDriver.Create();
        var endpoint = NetworkEndPoint.AnyIpv4;

        endpoint.Port = 12345;

        if (m_Driver.Bind(endpoint) != 0)
        {
            Debug.Log("Failed to bind to port 12345");
        }
        else
        {
            m_Driver.Listen();
        }

        m_Connections = new NativeList <NetworkConnection>(2, Allocator.Persistent);
    }
コード例 #14
0
    private void Start()
    {
        Debug.Log("[Notice] Setting up server...");

        m_clientIDDict = new Dictionary <int, NetworkObjects.NetworkPlayer>();
        m_Driver       = NetworkDriver.Create();
        var endpoint = NetworkEndPoint.AnyIpv4; //Get this server side IP

        endpoint.Port = serverPort;             // Apply server port

        //Try to bind driver to address
        if (m_Driver.Bind(endpoint) != 0)
        {
            Debug.LogError("[Error] Failed to bind to port " + serverPort);
        }
        else
        {
            m_Driver.Listen(); //Start listening for messages on successful bind
        }
        Debug.Log("[Notice] Server Ready.");

        m_Connections = new NativeList <NetworkConnection>(16, Allocator.Persistent); //Set initial capacity to 16, set memory allocation to persistent (?)

        StartCoroutine(UpdateClientsRoutine(m_serverUpdateInterval));
    }
コード例 #15
0
    public static void StartServer()
    {
        Console.Log("Starting server..");

        var config = new NetworkConfigParameter
        {
            connectTimeoutMS    = CONNECT_TIMEOUT,
            disconnectTimeoutMS = DISCONNECT_TIMEOUT,
            maxConnectAttempts  = MAX_CONNECTION_ATTEMPTS
        };

        Driver = NetworkDriver.Create(config);
        var endpoint = NetworkEndPoint.AnyIpv4;

        endpoint.Port = PORT;
        if (Driver.Bind(endpoint) != 0)
        {
            Debug.Log("Failed to bind to port " + PORT);
        }
        else
        {
            Driver.Listen(); // Sets the NetworkDriver in the Listen state
        }

        connections = new NativeList <NetworkConnection>(MAX_CONNECTIONS, Allocator.Persistent);

        Console.Log("Server is up and running!");
    }
コード例 #16
0
    private void Awake()
    {
        if (instance == null)
        {
            instance = this;
        }
        else
        {
            Destroy(this);
        }

        m_Driver = NetworkDriver.Create();
        var endpoint = NetworkEndPoint.AnyIpv4;

        endpoint.Port = 12345;
        if (m_Driver.Bind(endpoint) != 0)
        {
            Debug.Log("Failed to Bind to Port9000"); //Its over 9000!
        }
        else
        {
            m_Driver.Listen();
        }

        m_Connections = new NativeList <NetworkConnection>(16, Allocator.Persistent);
        clients       = new List <Client>();
        players       = new List <GameObject>();
    }
コード例 #17
0
    // Start is called before the first frame update
    void Start()
    {
        serverDataHolder = new ServerDataHolder();

        networkDriver = NetworkDriver.Create();

        NetworkEndPoint endPoint = NetworkEndPoint.AnyIpv4; //might use var instead

        endPoint.Port = 9000;

        if (!Tools.LOCAL)
        {
            endPoint = NetworkEndPoint.Parse(Tools.IP, 9000);
        }

        if (networkDriver.Bind(endPoint) != 0)
        {
            Debug.Log("Failed to bind port to" + endPoint.Port);
        }
        else
        {
            networkDriver.Listen();
        }

        connections = new NativeList <NetworkConnection>(16, Allocator.Persistent);

        messagesQueue = new Queue <MessageHeader>();

        for (int i = 0; i < ServerCallbacks.Length; i++)
        {
            ServerCallbacks[i] = new MessageEvent();
        }
        ServerCallbacks[(int)MessageHeader.MessageType.setName].AddListener(HandleSetName);
    }
コード例 #18
0
        public void IPC_Setup()
        {
            Driver = TestNetworkDriver.Create(new NetworkDataStreamParameter {
                size = 64
            });
            RemoteDriver = TestNetworkDriver.Create(new NetworkDataStreamParameter {
                size = 64
            });

            RemoteDriver.Bind(NetworkEndPoint.LoopbackIpv4);
            RemoteDriver.Listen();
        }
コード例 #19
0
        public void IPC_Setup()
        {
            Driver = TestNetworkDriver.Create(new NetworkDataStreamParameter {
                size = 64
            });
            RemoteDriver = TestNetworkDriver.Create(new NetworkDataStreamParameter {
                size = 64
            });

            RemoteDriver.Bind(NetworkEndPoint.LoopbackIpv4);
            RemoteDriver.Listen();
            ToRemoteConnection = Driver.Connect(RemoteDriver.LocalEndPoint());
            Driver.ScheduleFlushSend(default).Complete();
コード例 #20
0
        public void Start(NetworkDriver serverDriver)
        {
            if (IsActive)
            {
                serverDriver.Dispose();
                throw new InvalidOperationException("Cannot start server: is already active");
            }

            if (!_initialized)
            {
                serverDriver.Dispose();
                throw new InvalidOperationException("Cannot start server: not initialized. You must call Init() first");
            }

            if (_serverDriver.IsCreated)
            {
                _serverDriver.Dispose();
            }
            _serverDriver       = serverDriver;
            _unreliablePipeline = _useSimulationPipeline
                ? _serverDriver.CreatePipeline(typeof(SimulatorPipelineStage))
                : NetworkPipeline.Null;
            _reliablePipeline = _useSimulationPipeline
                ? _serverDriver.CreatePipeline(typeof(ReliableSequencedPipelineStage), typeof(SimulatorPipelineStage))
                : _serverDriver.CreatePipeline(typeof(ReliableSequencedPipelineStage));
            _connections = new NativeList <NetworkConnection>(16, Allocator.Persistent);

            foreach (ushort port in _ports)
            {
                _endPoint.Port = port;
                if (_serverDriver.Bind(_endPoint) != 0)
                {
                    continue;
                }
                _serverDriver.Listen();
                State = ServerState.Started;
                Debug.Log($"Started server on port {_endPoint.Port}");
                break;
            }

            if (State != ServerState.Started)
            {
                _connections.Dispose();
                _serverDriver.Dispose();
                Application.Quit(-1);
                throw new NetException("Failed to bind to any port");
            }
        }
コード例 #21
0
        public void SetupServerAndClientAndConnectThem(int bufferSize)
        {
            //setup server
            server_driver = NetworkDriver.Create(new NetworkDataStreamParameter {
                size = bufferSize
            });
            NetworkEndPoint server_endpoint = NetworkEndPoint.LoopbackIpv4;

            server_endpoint.Port = 1337;
            var ret      = server_driver.Bind(server_endpoint);
            int maxRetry = 10;

            while (ret != 0 && --maxRetry > 0)
            {
                server_endpoint.Port += 17;
                ret = server_driver.Bind(server_endpoint);
            }
            ;
            Assert.AreEqual(ret, 0, "Failed to bind the socket");
            server_driver.Listen();

            //setup client
            client_driver = NetworkDriver.Create(new NetworkDataStreamParameter {
                size = bufferSize
            });
            clientToServerConnection = client_driver.Connect(server_endpoint);

            //update drivers
            client_driver.ScheduleUpdate().Complete();

            for (int i = 0; i < 10; ++i)
            {
                server_driver.ScheduleUpdate().Complete();
                //accept connection
                connectionToClient = server_driver.Accept();
                if (connectionToClient.IsCreated)
                {
                    break;
                }
            }
            Assert.IsTrue(connectionToClient.IsCreated, "Failed to accept the connection");

            ev = PollDriverAndFindDataEvent(ref server_driver, connectionToClient, NetworkEvent.Type.Empty);
            Assert.IsTrue(ev == NetworkEvent.Type.Empty, $"Not empty NetworkEvent on the server appeared, got {ev} using {backend}");

            ev = PollDriverAndFindDataEvent(ref client_driver, clientToServerConnection, NetworkEvent.Type.Connect);
            Assert.IsTrue(ev == NetworkEvent.Type.Connect, $"NetworkEvent should have Type.Connect on the client, but got {ev} using {backend}");
        }
コード例 #22
0
        public bool Listen(NetworkEndPoint endpoint)
        {
            if (Driver.Bind(endpoint) != 0)
            {
                Debug.Log($"Failed to bind to port {endpoint.Port}!");
                return(false);
            }

            if (Driver.Listen() != 0)
            {
                Debug.Log($"Listen Error!");
            }

            _driverListening = true;
            return(true);
        }
コード例 #23
0
 public bool Listen(NetworkEndPoint endpoint)
 {
     LastDriverWriter.Complete();
     // Switching to server mode
     if (m_Driver.Bind(endpoint) != 0)
     {
         return(false);
     }
     if (m_Driver.Listen() != 0)
     {
         return(false);
     }
     m_DriverListening  = true;
     m_ConcurrentDriver = m_Driver.ToConcurrent();
     return(true);
 }
コード例 #24
0
    void Start()
    {
        m_Driver = NetworkDriver.Create();
        var endpoint = NetworkEndPoint.AnyIpv4;

        endpoint.Port = serverPort;
        if (m_Driver.Bind(endpoint) != 0)
        {
            Debug.Log("Failed to bind to port " + serverPort);
        }
        else
        {
            m_Driver.Listen();
        }
        m_connections = new NativeList <NetworkConnection>(16, Allocator.Persistent);
    }
コード例 #25
0
ファイル: ServerController.cs プロジェクト: LeoVC1/Unity-UDP
    void Start()
    {
        m_Driver = NetworkDriver.Create();
        var endPoint = NetworkEndPoint.AnyIpv4;

        endPoint.Port = 9000;
        if (m_Driver.Bind(endPoint) != 0)
        {
            Debug.Log("Erro! Porta ja esta sendo usada!");
        }
        else
        {
            m_Driver.Listen();
        }

        m_Connections = new NativeList <NetworkConnection>(16, Allocator.Persistent);
    }
コード例 #26
0
 public bool Listen(NetworkEndPoint endpoint)
 {
     LastDriverWriter.Complete();
     // Switching to server mode
     if (m_Driver.Bind(endpoint) != 0)
     {
         return(false);
     }
     if (m_Driver.Listen() != 0)
     {
         return(false);
     }
     m_DriverListening = true;
     // FIXME: Bind breaks all copies of the driver nad makes them send to the wrong socket
     m_ConcurrentDriver = m_Driver.ToConcurrent();
     return(true);
 }
コード例 #27
0
    void Awake()
    {
        m_Driver = NetworkDriver.Create();
        var endpoint = NetworkEndPoint.AnyIpv4;

        endpoint.Port = m_ServerPort;
        if (m_Driver.Bind(endpoint) != 0)
        {
            //flag error
        }
        else
        {
            m_Driver.Listen();
        }
        m_Connections    = new NativeList <NetworkConnection>(16, Allocator.Persistent);
        m_Rooms          = new List <GameObject>();
        m_NetworkPlayers = new List <C4NO.NetworkPlayer>(16);
    }
コード例 #28
0
    void Start()
    {
        // Create the server driver, bind it to a port and start listening for incoming connections
        m_ServerDriver = NetworkDriver.Create();
        var addr = NetworkEndPoint.AnyIpv4;

        addr.Port = 9000;
        if (m_ServerDriver.Bind(addr) != 0)
        {
            Debug.Log("Failed to bind to port 9000");
        }
        else
        {
            m_ServerDriver.Listen();
        }

        m_connections = new NativeList <NetworkConnection>(16, Allocator.Persistent);
    }
コード例 #29
0
    private void Awake()
    {
        m_Driver = NetworkDriver.Create();
        var endpoint = NetworkEndPoint.AnyIpv4;

        endpoint.Port = 12345;
        if (m_Driver.Bind(endpoint) != 0)
        {
            Debug.Log("Failed to bind port");
        }
        else
        {
            m_Driver.Listen();
        }

        m_Connections = new NativeList <NetworkConnection>(16, Allocator.Persistent);
        clients       = new List <Client>();
        players       = new List <GameObject>();
    }
コード例 #30
0
    void Start()
    {
        Debug.Log("Initialized.");
        m_Driver = NetworkDriver.Create();
        var endpoint = NetworkEndPoint.AnyIpv4;

        endpoint.Port = serverPort;
        if (m_Driver.Bind(endpoint) != 0)
        {
            Debug.Log("Failed to bind to port " + serverPort);
        }
        else
        {
            m_Driver.Listen();
        }

        m_Connections = new NativeList <NetworkConnection>(16, Allocator.Persistent);
        InvokeRepeating("HandShake", 0.0f, 2.0f);
    }