feat: finish normal binding socket example

This commit is contained in:
2026-05-20 12:25:50 -04:00
parent 3e6426c655
commit 9c957b0309
3 changed files with 18 additions and 3 deletions
+13 -2
View File
@@ -1,2 +1,13 @@
// See https://aka.ms/new-console-template for more information
Console.WriteLine("Hello, World!");
using System.Net;
using System.Net.Sockets;
using var socket = new Socket(SocketType.Stream, ProtocolType.Tcp);
await socket.ConnectAsync(new IPEndPoint(IPAddress.Loopback, 9000));
Console.WriteLine("Type into the console to echo the contents of your message.");
var ns = new NetworkStream(socket);
var readTask = Console.OpenStandardInput().CopyToAsync(ns);
var writeTask = ns.CopyToAsync(Console.OpenStandardOutput());
await Task.WhenAny(readTask, writeTask);