コード例 #1
0
    // Start
    void Start()
    {
        NetworkTransport.Init();

        reliableChannel   = config.AddChannel(QosType.Reliable);
        unreliableChannel = config.AddChannel(QosType.Unreliable);

        var hostTopology = new HostTopology(config, maxConnections);

        hostId = NetworkTransport.AddHost(hostTopology, port);

        receiveBuffer = new byte[bufferSize];

        onConnect += (connectionId) => {
            Debug.Log("Player " + connectionId + " connected.");

            var player = new NetworkTarget(connectionId);
            NetworkPlayers.Add(player);

            // Send connected message
            player.Send(ServerMessage.Connected);
        };

        onDisconnect += (connectionId) => {
            Debug.Log("Player " + connectionId + " disconnected.");
            NetworkPlayers.Remove(NetworkPlayers.Find(connectionId));
        };

        isStarted = true;
    }
コード例 #2
0
    public void Ping(NetworkTarget player, long timeStamp)
    {
        var ping = Utils.GetTimeStamp() - timeStamp;

        // Send ping back to client
        player.Send(ServerMessage.Ping, ping);
    }