private void ClientHandle(object obj) { Socket socket = obj as Socket; if (socket != null) { var stream = new MllpNetworkStream(socket, true) { ReadTimeout = 20000, WriteTimeout = 20000 }; try { while (true) { byte[] request = stream.ReadMessage(); if (HL7Setting.Default.LogRequestMessage) { LogAdapter.Logger.Info(string.Format("Receive an HL7 request message from {0} \n {1}", socket.RemoteEndPoint, Encoding.UTF8.GetString(request))); //Platform.Log( // LogLevel.Info, // "Receive an HL7 request message from {0} \n {1}", // socket.RemoteEndPoint.ToString(), // Encoding.UTF8.GetString(request)); } byte[] response = OnMessage(request); if (HL7Setting.Default.LogResponseMessage) { LogAdapter.Logger.Info(string.Format("Sending HL7 Response message to {0} \n {1}", socket.RemoteEndPoint, Encoding.UTF8.GetString(response))); //Platform.Log( // LogLevel.Info, // "Sending HL7 Response message to {0} \n {1}", // socket.RemoteEndPoint.ToString(), // Encoding.UTF8.GetString(response)); } stream.WriteMessage(response, 0, response.Length); } } catch (Exception ex) { LogAdapter.Logger.TraceException(ex); //Platform.Log(LogLevel.Warn, ex); } finally { stream.Close(); } } }
public byte[] Send(byte[] request) { if (!_client.Connected) { _client.Connect(_hostName, _port); } MllpNetworkStream stream = new MllpNetworkStream(_client.Client) { ReadTimeout = 20000, WriteTimeout = 20000 }; stream.WriteMessage(request, 0, request.Length); return(stream.ReadMessage()); }