Created
March 26, 2020 11:23
-
-
Save ravage/37fc974f7860ce61824c16d943577555 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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