You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
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}");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|