Exemple #1
0
        /// <summary>
        /// Register the server's UDP port.
        /// </summary>
        /// <param name="message">The UDP port message from the server.</param>
        public void HandleUdpPortMessage(UdpPortMessage <Server> message)
        {
            _serverUdpEndpoint      = (IPEndPoint)_tcpServer.Client.RemoteEndPoint;
            _serverUdpEndpoint.Port = message.Port;

            Task.Run(() => ReceiveData(_udpClient, _serverUdpEndpoint).ConfigureAwait(false));
            Task.Run(() => SendUdpPortToServer().ConfigureAwait(false));
        }
Exemple #2
0
        /// <summary>
        /// Register a client's local UDP port.
        /// </summary>
        /// <param name="message">The UDP port message.</param>
        public void HandleUdpPortMessage(UdpPortMessage <Client> message)
        {
            foreach (Player player in _players.Values)
            {
                if (player.Secret != message.Secret)
                {
                    continue;
                }

                player.UdpEndpoint      = (IPEndPoint)player.TcpClient.Client.RemoteEndPoint;
                player.UdpEndpoint.Port = message.Port;

                Task.Run(() => ReceiveData(_udpClient, player.UdpEndpoint).ConfigureAwait(false));

                UdpPortsExchanged(this, new UdpPortsExchangedEventArgs(player));

                return;
            }
        }
Exemple #3
0
 override public byte[] GetBytes(UdpPortMessage <TSender> message)
 => Build().UShort(message.Port).String(message.Secret).Data;