class SocketSerever
{
public static void Main()
{
byte[] bytes = new byte[1024];
IPHostEntry ipHost = Dns.Resolve("localhost");
IPAddress ipAdress = ipHost.AddressList[0];
IPEndPoint ipEndPoint = new IPEndPoint(ipAdress, 11111);
Socket sListener = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
sListener.Bind(ipEndPoint);
sListener.Listen(10);
while (true)
{
Socket handler = sListener.Accept();
handler.Receive(bytes);
string receiveMessage = Encoding.ASCII.GetString(bytes);
handler.Shutdown(SocketShutdown.Both);
handler.Close();
}
}
}
class ClientSocket
{
public static void Main()
{
Serializations serialization = new Serializations();
IPHostEntry ipHost = Dns.Resolve("127.0.0.1");
IPAddress ipAddr = ipHost.AddressList[0];
IPEndPoint ipEndPoint = new IPEndPoint(ipAddr, 11111);
Socket sender = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
sender.Connect(ipEndPoint);
string message = "Helo server!";
byte[] buffer = Encoding.ASCII.GetBytes(message);
sender.Send(buffer);
sender.Shutdown(SocketShutdown.Both);
sender.Close();
}
}