Hello. I have written a TCP server. Then I am trying to connect to my server used Telnet (telnet localhost 2200). Problem: telnet write bad text - like this: ? ?????...
static void Main(string[] args)
{
ASCIIEncoding encoding = new ASCIIEncoding();
//UnicodeEncoding encoding = new UnicodeEncoding();
Byte[] message = encoding.GetBytes("Я занят...");
try
{
IPAddress localAddress = IPAddress.Parse("127.0.0.1");
TcpListener listener = new TcpListener(localAddress,2200);
listener.Start(1);
while (true)
{
Console.WriteLine("Сервер ожидает {0}", listener.LocalEndpoint);
TcpClient client = listener.AcceptTcpClient();
NetworkStream io = client.GetStream();
Console.WriteLine("Принято соединение от {0}", client.Client.RemoteEndPoint);
Console.WriteLine("Отправляем сообщение...");
io.Write(message,0,message.Length);
Console.WriteLine("Закрытие соединения");
client.Close();
}
}
catch (Exception e)
{
Console.WriteLine("Произошла ошибка {0}", e.Message);
}
}
The text on Russian language.If text on English then OK. What is the problem, may be codepage? Thanks and sorry for my bad English.