tap (task-based asynchronous pattern)
This commit is contained in:
24
TAP/Client/Client.cs
Normal file
24
TAP/Client/Client.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user