private static string HandleMessage(string data) { Console.WriteLine("Received message"); var msg = new Message(); msg.Parse(data); Console.WriteLine("Parsed message : {0}", msg.MessageType()); Console.WriteLine("Message timestamp : {0}", msg.MessageDateTime()); Console.WriteLine("Message control id : {0}", msg.MessageControlId()); // ********************************************************************* // Here you could do something usefull with the received message ;-) // ********************************************************************* // todo // Create a response message // var response = new Message(); var msh = new Segment("MSH"); msh.Field(2, "^~\\&"); msh.Field(7, DateTime.Now.ToString("yyyyMMddhhmmsszzz")); msh.Field(9, "ACK"); msh.Field(10, Guid.NewGuid().ToString()); msh.Field(11, "P"); msh.Field(12, "2.5.1"); response.Add(msh); var msa = new Segment("MSA"); msa.Field(1, "AA"); msa.Field(2, msg.MessageControlId()); response.Add(msa); // Put response message into an MLLP frame ( <VT> data <FS><CR> ) // var frame = new StringBuilder(); frame.Append((char)0x0B); frame.Append(response.Serialize()); frame.Append((char)0x1C); frame.Append((char)0x0D); return(frame.ToString()); }