echo server
This commit is contained in:
38
Echo/Client/Client.cs
Normal file
38
Echo/Client/Client.cs
Normal 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
10
Echo/Client/Client.csproj
Normal 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>
|
Reference in New Issue
Block a user