Skip to content

Instantly share code, notes, and snippets.

@lukasz-pyrzyk
Last active March 13, 2016 20:25
Show Gist options
  • Save lukasz-pyrzyk/a12d487972181b20aba5 to your computer and use it in GitHub Desktop.
Save lukasz-pyrzyk/a12d487972181b20aba5 to your computer and use it in GitHub Desktop.
TcpListener listener = new TcpListener(IPAddress.Any, 55);
listener.Start();
TcpClient client = await listener.AcceptTcpClientAsync();
byte[] request;
using (NetworkStream ns = client.GetStream())
{
using (MemoryStream ms = new MemoryStream())
{
int i;
int bufferSize = 1024 * 2;
byte[] buffer = new byte[bufferSize];
while ((i = ns.Read(buffer, 0, buffer.Length)) != 0)
{
await ms.WriteAsync(buffer, 0, i);
buffer = new Byte[bufferSize];
}
request = ms.ToArray();
}
}
ProcessClientRequest(request);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment