public ReceivedPacket(ConnectionManager connectionManager, TcpPacket packet) { this.connectionManager = connectionManager; this.packet = packet; }
/// <summary> /// Handles the received data trough blackboard Tcp Socket Server /// </summary> /// <param name="p">Tcp Packet received</param> private void server_DataReceived(TcpPacket p) { if (p.IsAnsi) { dataReceived.Produce(p); for(int i = 0; i < p.DataStrings.Length; ++i) Log.WriteLine(5, "SERVER <= " + p.DataStrings[i]); Log.WriteLine(6, dataReceived.Count.ToString() + " messages pending to parse"); } }
/// <summary> /// Parses data received trough socket spliting merged packets /// </summary> /// <param name="s">socket which received the data</param> /// <param name="data">Received data buffer</param> protected virtual TcpPacket ParseReceivedData(Socket s, byte[] data) { TcpPacket packet = new TcpPacket(s, data, 0, data.Length); if (DataReceived != null) { DataReceived(packet); } return(packet); /* * int i; * bool binaryPakage = false; * TcpPacket packet = null; * * // Check if is string suitable * i = 0; * while ((i < data.Length) && (data[i] != 0)) * { * if (data[i] > 127) * { * binaryPakage = true; * break; * } ++i; * } * * if (binaryPakage) * { * packet = new TcpPacket(s, data, 0, data.Length); * if (DataReceived != null) * DataReceived(packet); * //lastString = packet.DataString; * } * else * { * int count = 0; * byte[] segment; * * System.IO.MemoryStream ms = new System.IO.MemoryStream(data.Length); * for (i = 0; (i < data.Length) && (data[i] < 127); ++i) * { * if ((data[i] == 0) && (ms.Position > 0)) * { * segment = ms.ToArray(); * packet = new TcpPacket(s, segment, 0, segment.Length); * if (DataReceived != null) DataReceived(packet); * ms.Close(); * ms = new System.IO.MemoryStream(data.Length); * count = 0; * continue; * } * ms.WriteByte(data[i]); * count++; * data[i] = 0; * } * //if (ms.Position == received) * //{ * // segment = ms.ToArray(); * // packet = new TcpPacket(s, segment, 0, segment.Length); * // if (DataReceived != null) DataReceived(packet); * //} * //if (packet != null) lastString = packet.DataString; * } * * // Clear buffer * return packet; */ }
/// <summary> /// Stores the received packet in a ProducerConsumer queue /// </summary> /// <param name="cnnMan">The ConnectionManager source of the data</param> /// <param name="packet">The received TCP packet</param> private void cnnMan_DataReceived(ConnectionManager cnnMan, TcpPacket packet) { if (!packet.IsAnsi) return; dataReceived.Produce(packet); }
/// <summary> /// Manages the DataReceived event of the ConnectionManager /// </summary> /// <param name="p">Received data</param> private void connectionManager_DataReceived(ConnectionManager connectionManager, TcpPacket packet) { #if DEBUG if (!packet.IsAnsi) return; for (int i = 0; i < packet.DataStrings.Length; ++i) { Console("Rcv: " + "[" + packet.RemoteEndPoint.Address.ToString() + "] " + packet.DataStrings[i]); } #endif }
private void server_DataReceived(TcpPacket p) { CommandBase m; ParseMessage(p.DataString, out m); if (MessageReceived != null) MessageReceived(m); }
private void cnnMan_DataReceived(ConnectionManager cnnMan, TcpPacket packet) { dataReceived.Produce(new ReceivedPacket(cnnMan, packet)); }
private void server_DataReceived(TcpPacket p) { string text; #if BENCHMARK stopwatch.Stop(); textForServerConsole = stopwatch.Elapsed.ToString(); this.Invoke(updateServerConsoleEH); #endif if (!p.IsAnsi) { System.Text.StringBuilder sb = new System.Text.StringBuilder(p.Data.Length + 10); for (int i = 0; i < p.Data.Length; ++i) { sb.Append(' '); sb.Append(p.Data[i].ToString("X2")); } text = sb.ToString(); textForServerConsole = "[" + p.SenderIP.ToString() + "] (" + p.Data.Length + "bytes): " + text; this.Invoke(updateServerConsoleEH); } else { textForServerConsole = "[" + p.SenderIP.ToString() + "] (" + p.Data.Length + "bytes): "; this.Invoke(updateServerConsoleEH); for (int i = 0; i < p.DataStrings.Length; ++i) { text = p.DataStrings[i]; textForServerConsole = "\t[" + p.SenderIP.ToString() + "] (Part " + i + "): " + text; this.Invoke(updateServerConsoleEH); } } /* text = p.DataString; if ((text.Length < 1) || ((p.Data.Length != text.Length) && (p.Data.Length != text.Length + 1))) { System.Text.StringBuilder sb = new System.Text.StringBuilder(p.Data.Length + 10); //sb.Append(p.Data.Length.ToString()); //sb.Append("bytes"); for (int i = 0; i < p.Data.Length; ++i) { sb.Append(' '); sb.Append(p.Data[i].ToString("X2")); } text = sb.ToString(); } textForServerConsole = "[" + p.SenderIP.ToString() + "] ("+ p.Data.Length +"bytes): " + text; this.Invoke(updateServerConsoleEH); */ }