Skip to content

Instantly share code, notes, and snippets.

@ravage
Created March 26, 2020 11:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ravage/37fc974f7860ce61824c16d943577555 to your computer and use it in GitHub Desktop.
Save ravage/37fc974f7860ce61824c16d943577555 to your computer and use it in GitHub Desktop.
static void Main(string[] args)
{
Run().GetAwaiter().GetResult();
}
static async Task Run()
{
TcpClient client = new TcpClient("127.0.0.1", 8080);
NetworkStream stream = client.GetStream();
while (true)
{
byte[] readBuffer = new byte[128];
byte[] writeBuffer = new byte[128];
string input = Console.ReadLine();
int len = Encoding.ASCII.GetByteCount(input);
writeBuffer[0] = 0x41;
writeBuffer[1] = (byte) len;
Encoding.ASCII.GetBytes(input, 0, len, writeBuffer,2);
await stream.WriteAsync(writeBuffer);
int bytesCount = await stream.ReadAsync(readBuffer);
Console.WriteLine(Encoding.ASCII.GetString(readBuffer[2..(2 + bytesCount)]));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment