public static async void RunServer(this VSCodeDebugAdapter session, int port, CancellationToken token) { TcpListener serverSocket = new TcpListener(IPAddress.Loopback, port); serverSocket.Start(); Console.WriteLine($"StartListening at {serverSocket.LocalEndpoint}"); token.Register(() => { Console.WriteLine("Shuting down Server"); serverSocket.Stop(); }); while (!token.IsCancellationRequested) { var clientSocket = await serverSocket.AcceptSocketAsync(); if (clientSocket != null) { Console.WriteLine(">> accepted connection from client"); using (var networkStream = new NetworkStream(clientSocket)) { try { await session.Start(networkStream, networkStream); } catch (Exception e) { Console.Error.WriteLine("Exception: " + e); } } Console.Error.WriteLine(">> client connection closed"); } } }
public static async void RunClient(this VSCodeDebugAdapter session, int port, CancellationToken token) { TcpClient client = new TcpClient(); await client.ConnectAsync(IPAddress.Loopback, port); token.Register(() => { Console.WriteLine("Shuting down client"); session.Stop(); client.Dispose(); }); var stream = client.GetStream(); session.Start(stream, stream); }