private async Task Respond(TcpClient client, byte[] data, CancellationToken cancellation) { byte[] response; if (data[0] == (byte)0) { response = await codec.DecodeBinaryXML(new ArraySegment <byte>(data, 1, data.Length - 1).ToArray(), false).ConfigureAwait(false); } else if (data[0] == (byte)1) { response = await codec.EncodeBinaryXML(new ArraySegment <byte>(data, 1, data.Length - 1).ToArray()).ConfigureAwait(false); } else { response = new byte[0]; } try { await client.GetStream().WriteAsync(response, 0, response.Length, cancellation).ConfigureAwait(false); await client.GetStream().FlushAsync().ConfigureAwait(false); } catch (Exception e) { Console.WriteLine(e.Message); Console.WriteLine(e.StackTrace); } }
public byte[] EncodeBinaryXML(string xml) { if (String.IsNullOrEmpty(xml.Trim())) { return(null); } return(m_wcfBinaryCodec.EncodeBinaryXML(xml)); }