echo server

This commit is contained in:
2023-02-06 13:11:18 +09:00
parent 6000d5a4e7
commit 8e51b3d046
7 changed files with 148 additions and 0 deletions

38
Echo/Client/Client.cs Normal file
View File

@@ -0,0 +1,38 @@
using System.Net;
using System.Net.Sockets;
using System.Text;
namespace Client;
internal class Client
{
static void Main(string[] args)
{
using (Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
{
IPEndPoint endPoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 20000);
socket.Connect(endPoint);
while (true)
{
string str = Console.ReadLine();
if (str == "exit")
return;
byte[] buffer = Encoding.UTF8.GetBytes(str);
socket.Send(buffer);
byte[] buffer2 = new byte[256];
int byteRead = socket.Receive(buffer2);
if (byteRead < 1)
{
Console.WriteLine("Disconnecting server...");
return;
}
string str2 = Encoding.UTF8.GetString(buffer2);
Console.WriteLine($"[Receive] {str2}");
}
}
}
}

10
Echo/Client/Client.csproj Normal file
View File

@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>