-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
40 lines (27 loc) · 1.02 KB
/
Copy pathProgram.cs
File metadata and controls
40 lines (27 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
using System.Net;
using System.Text;
using SquidStd.Network.Client;
using SquidStd.Network.Server;
#region step-1
var endPoint = new IPEndPoint(IPAddress.Loopback, 9099);
var server = new SquidTcpServer(endPoint);
server.OnClientConnect += (_, args) =>
Console.WriteLine($"Client connected: session {args.Client.SessionId}");
server.OnDataReceived += (_, args) =>
Console.WriteLine(
$"Received {args.Data.Length} byte(s): {Encoding.UTF8.GetString(args.Data.Span)}"
);
#endregion
if (!args.Contains("--run"))
{
Console.WriteLine("Pass --run to start the TCP server and round-trip a message.");
return;
}
#region step-2
await server.StartAsync(CancellationToken.None);
var client = await SquidStdTcpClient.ConnectAsync(endPoint);
await client.SendAsync(Encoding.UTF8.GetBytes("hello squid"), CancellationToken.None);
await Task.Delay(200);
await client.DisposeAsync();
await server.DisposeAsync();
#endregion