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 Server;
|
|
|
|
|
|
|
|
|
|
internal class Server
|
|
|
|
|
{
|
|
|
|
|
static void Main(string[] args)
|
|
|
|
|
{
|
|
|
|
|
using (Socket serverSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
|
|
|
|
|
{
|
|
|
|
|
IPEndPoint endPoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 20000);
|
|
|
|
|
serverSocket.Bind(endPoint);
|
|
|
|
|
serverSocket.Listen(20);
|
|
|
|
|
|
|
|
|
|
using (Socket clientSocket = serverSocket.Accept())
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine(clientSocket.RemoteEndPoint);
|
|
|
|
|
|
|
|
|
|
while (true)
|
|
|
|
|
{
|
|
|
|
|
byte[] buffer = new byte[256];
|
|
|
|
|
int totalBytes = clientSocket.Receive(buffer);
|
|
|
|
|
if (totalBytes < 1)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("Disconnecting client...");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
string str = Encoding.UTF8.GetString(buffer);
|
|
|
|
|
Console.WriteLine(str);
|
|
|
|
|
|
|
|
|
|
clientSocket.Send(buffer);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|