tap (task-based asynchronous pattern)

This commit is contained in:
2023-02-07 14:44:58 +09:00
parent cb8fba64b1
commit f74090a49e
7 changed files with 142 additions and 0 deletions

24
TAP/Client/Client.cs Normal file
View File

@@ -0,0 +1,24 @@
using System.Net;
using System.Net.Sockets;
using System.Text;
namespace Client
{
internal class Client
{
static async Task Main(string[] args)
{
Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
IPEndPoint endPoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 20000);
await socket.ConnectAsync(endPoint);
while (true)
{
string str = Console.ReadLine() ?? string.Empty;
byte[] buffer = Encoding.UTF8.GetBytes(str);
await socket.SendAsync(buffer, SocketFlags.None);
}
}
}
}