Esempio n. 1
0
 protected virtual void OnClientDisconnected(TCPClientThread client, string reason)
 {
     if (ClientDisconnected != null)
     {
         ClientDisconnected(client, reason);
     }
 }
Esempio n. 2
0
 /// <summary>
 /// 监听线程
 /// </summary>
 private void TCPListenerHandler()
 {
     while (true)
     {
         try
         {
             Socket     clientSocket = _socket.Accept();
             IPEndPoint ep           = (IPEndPoint)clientSocket.RemoteEndPoint;
             log.Info("已接收到客户端 " + ep.Address.ToString() + " 连接请求,正在分派客户端处理线程");
             TCPClientThread client = new TCPClientThread(clientSocket);
             client.IPAddress = ep.Address.ToString();
             _clients.Add(client);
             client.ClientDisconnected += Client_ClientDisconnected;
             client.OPCItemUpdated     += Client_OPCItemUpdated;
             client.Start();
         }
         catch (Exception ex) { log.Error(ex.Message); }
     }
 }
Esempio n. 3
0
 protected virtual void OnOPCItemUpdated(string blockName, string newValue, string type, TCPClientThread client)
 {
     if (OPCItemUpdated != null)
     {
         OPCItemUpdated(blockName, newValue, type, client);
     }
 }
Esempio n. 4
0
 /// <summary>
 /// 接收客户端处理线程返回的断开事件并清理客户端连接列表
 /// </summary>
 /// <param name="client">断开的客户端</param>
 /// <param name="reason">断开的原因</param>
 private void Client_ClientDisconnected(TCPClientThread client, string reason)
 {
     log.Info("检测到客户端 " + client.IPAddress + " 已断开连接,正在清理处理线程 断线原因:" + reason);
     client.Terminate();
     _clients.Remove(client);
 }
Esempio n. 5
0
 /// <summary>
 /// 接收客户端处理线程返回的OPCITEM更新请求并转发给主程序
 /// </summary>
 /// <param name="blockName">要更新的地址块</param>
 /// <param name="newValue">更新的值</param>
 private void Client_OPCItemUpdated(string blockName, string newValue, string type, TCPClientThread client)
 {
     log.Debug("接收到客户端 " + client.IPAddress + " 处理线程返回的OPCITEM更新事件,正在向主程序转发");
     OnOPCItemUpdated(blockName, newValue, type);
 }