Пример #1
0
        void server_ClientAccepted(object sender, TcpServerClientEventArgs <TcpAsyncClient> e)
        {
            this.client            = e.Client;
            e.Client.Received     += server_DataReceived;
            e.Client.Disconnected += Client_Disconnected;

            Ip     = ((IPEndPoint)(e.Client.RemoteEndPoint)).Address.MapToIPv4().ToString();
            Status = DeviceState.已连接.ToString();

            logger.Info("Camera Client Connected:" + e.Client.RemoteEndPoint.ToString());
        }
Пример #2
0
        void Client_Disconnected(object sender, EventArgs e)
        {
            TcpAsyncClient client = sender as TcpAsyncClient;

            IPEndPoint ipEnd   = (IPEndPoint)(client.RemoteEndPoint);
            string     ip      = ipEnd.Address.ToString();
            int        lightId = LightController.GetLightIdFromIpAddr(ip);

            //设置灯为不可用状态
            DbHelper.SetLightIsGood(lightId, false);
            lightSenders.Remove(lightId);
        }
Пример #3
0
 public void Dispose()
 {
     if (client != null)
     {
         try
         {
             client.Close();
             client = null;
         }
         catch (System.Exception ex)
         {
         }
     }
 }
Пример #4
0
        public override void Initialize()
        {
            if (IsHosted)
            {
                _udpServer = new UdpServer(12345, 11000, "GDarts");
                _udpServer.StartListen();
                TcpAsyncServer.StartTcpServer();
            }

            ConnectionManager connection;

            if (IP != null)
            {
                if (Port != null)
                {
                    connection = new ConnectionManager(IP, Port.Value);
                }
                else
                {
                    connection = new ConnectionManager(IP, Game.ConfigManager.TcpPort);
                }
            }
            else
            {
                var udpClient = new UdpClient("GDarts", 11000, 3000);
                if (udpClient.SendToBroadcast())
                {
                    connection = new ConnectionManager(IPAddress.Parse(udpClient.ServerAddress.Address.ToString()),
                                                       udpClient.TcpPort);
                }
                else
                {
                    return;
                }
            }

            _client = new TcpAsyncClient(connection);
            _client.handleConnection += AddPlayerInLobby;
            _client.handleGame       += JoinGame;
            _client.SendFindLobbyMessage();


            base.Initialize();
        }
Пример #5
0
 void client_Disconnected(object sender, EventArgs e)
 {
     System.Diagnostics.Debug.WriteLine("Client Disconnect:" + client.RemoteEndPoint.ToString());
     client = null;
 }
Пример #6
0
 public CustomTcpClient(TcpAsyncClient c)
 {
     client               = c;
     client.Received     += client_Received;
     client.Disconnected += client_Disconnected;
 }