private void Server_DataSent(object sender, AsyncSocketSessionEventArgs e) { InternalLogger.Log.Info(String.Format("ScreenTcpServer向{0}:{1}[{2}]发送数据{3}成功", this.currentClient == null ? null : currentClient.Address, this.currentClient == null ? 0 : currentClient.Port, this.sessionId, Encoding.Default.GetString(e.DataTransferred))); }
protected void Client_DataReceived(object sender, AsyncSocketSessionEventArgs e) { try { if (e.DataTransferred == null) { InternalLogger.Log.Warn("接收到Display数据为空,不处理"); return; } InternalLogger.Log.Debug("接收到原始的display数据:" + e.DataTransferred.BytesToHexString()); } catch (Exception ex) { InternalLogger.Log.Error("处理数据接收事件出错:" + ex.Message); } }
protected void Client_Connected(object sender, AsyncSocketSessionEventArgs e) { try { InternalLogger.Log.Info(String.Format("DisplayTcpClient({0}:{1}[{2}])已经连接成功", this.serverIp, this.serverPort, this.sessionId)); connectStatus = true; if (Connected != null) { Connected(sender, new PivasEventArgs <TCPMessageEx>(new TCPMessageEx( this.serverIp, this.serverPort, null))); } } catch (Exception ex) { InternalLogger.Log.Error("处理连接成功后事件出错:" + ex.Message); } }
protected void Client_Disconnected(object sender, AsyncSocketSessionEventArgs e) { try { InternalLogger.Log.Info(String.Format("MOXATcpClient({0}:{1}[{2}])已经断开连接:", this.serverIp, this.serverPort, this.sessionId)); connectStatus = false; if (Disconnected != null) { Disconnected(sender, new PivasEventArgs <TCPMessage>(new TCPMessage( this.serverIp, this.serverPort, String.Empty))); } } catch (Exception ex) { InternalLogger.Log.Error("处理断开成功后事件出错:" + ex.Message); } }
private void Server_DataReceived(object sender, AsyncSocketSessionEventArgs e) { try { if (e.DataTransferred == null) { InternalLogger.Log.Warn("接收到需要显示的数据为空,不处理"); return; } string data = Encoding.Default.GetString(e.DataTransferred); InternalLogger.Log.Debug("接收到需要显示的数据:" + data); ParseData(data); } catch (Exception ex) { InternalLogger.Log.Error("处理数据接收事件出错:" + ex.Message); } }
private void Server_Connected(object sender, AsyncSocketSessionEventArgs e) { try { GetClientInfo();//成功后,获取客户端的信息 InternalLogger.Log.Info(String.Format("ScreenTcpServer与({0}:{1}[{2}])已经断开连接:", this.currentClient == null ? null : currentClient.Address, this.currentClient == null ? 0 : currentClient.Port, this.sessionId)); if (Connected != null) { Connected(sender, null); } } catch (Exception ex) { InternalLogger.Log.Error("处理连接成功后事件出错:" + ex.Message); } }
/// <summary> /// 接收瓶签号 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void Client_DataReceived(object sender, AsyncSocketSessionEventArgs e) { try { if (e.DataTransferred == null) { InternalLogger.Log.Warn("接收到瓶签号数据为空,不处理"); return; } string data = Encoding.Default.GetString(e.DataTransferred).Replace(StaticDictionary.SPLITTER, "");//过滤一下回传换行符 InternalLogger.Log.Debug("接收到原始的瓶签号数据:" + data); ParseMoxaData(data); } catch (Exception ex) { InternalLogger.Log.Error("处理数据接收事件出错:" + ex.Message); } }
static void tcpServer_DataReceived(object sender, AsyncSocketSessionEventArgs e) { try { //接收到的数据是e.DataTransferred,转化字符串显示 string result = Encoding.Default.GetString(e.DataTransferred); if (!string.IsNullOrEmpty(result)) { if (Int32.Parse(result) == 0) { Console.WriteLine("计费失败"); } else { Console.WriteLine("计费成功"); } } } catch (Exception ex) { Console.WriteLine(ex); } }
private void Client_DataSent(object sender, AsyncSocketSessionEventArgs e) { InternalLogger.Log.Info(String.Format("DisplayTcpClient({0}:{1}[{2}])发送数据{3}成功", this.serverIp, this.serverPort, this.sessionId, e.DataTransferred.BytesToHexString())); }
private void Client_DataSent(object sender, AsyncSocketSessionEventArgs e) { InternalLogger.Log.Info(String.Format("ScreenTcpClient({0}:{1}[{2}])发送数据{3}成功", this.serverIp, this.serverPort, this.sessionId, Encoding.Default.GetString(e.DataTransferred))); }
static void tcpServer_Connected(object sender, AsyncSocketSessionEventArgs e) { Console.WriteLine("tcpServer_Connected"); GetClientInfo();//成功后,获取客户端的信息 }
static void tcpServer_DataSent(object sender, AsyncSocketSessionEventArgs e) { Console.WriteLine("tcpServer_DataSent"); }
static void tcpServer_Disconnected(object sender, AsyncSocketSessionEventArgs e) { Console.WriteLine("tcpServer_Disconnected"); }