Answer the question
In order to leave comments, you need to log in
How to run a server in C# on a VPS?
I created a server and a client on my computer - everything works fine. I decided to upload my application server to a virtual server on Windows Server 2016, but my server does not work on it. But the fact is that the application port (18888, tried others) does not open, what I tried:
1. Turning off the firewall completely - did not help 2. Turned
the
firewall back on and allowed its port in incoming and outgoing connections - did not help
that is, it cannot block the application from running.
netstat -a gives the following information:
this is provided that: IPHostEntry iPHost = Dns.GetHostEntry("localhost");
tried instead of localhost, enter the ip-address of the server - did not help
The client of my application cannot be connected from other computer to the server. The site 2ip.ru also writes that port 18888 is closed? How to solve the problem?
===
Current server code:
static void Main(string[] args)
{
TcpListener server = null;
try
{
int MaxThreadsCount = Environment.ProcessorCount * 4;
ThreadPool.SetMaxThreads(MaxThreadsCount, MaxThreadsCount);
ThreadPool.SetMinThreads(2, 2);
Int32 port = 18888;
IPAddress ipAddr = Dns.Resolve(IPAddress.Any.ToString()).AddressList[0];
int counter = 0;
server = new TcpListener(ipAddr, port);
Console.WriteLine("Конфигурация многопоточного сервера:");
Console.WriteLine(" Порт: " + port.ToString());
Console.WriteLine(" Потоки: " + MaxThreadsCount.ToString());
Console.WriteLine("\nСервер запущен\n");
server.Start();
while (true)
{
Console.Write("\nОжидаем соединения");
ThreadPool.QueueUserWorkItem(ClientProcessing, server.AcceptTcpClient());
counter++;
Console.Write("\nСоединение №" + counter.ToString() + "!");
}
}catch (SocketException e)
{
Console.WriteLine("SocketException: {0}", e);
}
finally
{
server.Stop();
}
Console.WriteLine("\nНажмите Enter...");
Console.Read();
}
Answer the question
In order to leave comments, you need to log in
Everything is written in the docs, in theory you need to register the binding port in application.json
After the appearance of the source code, everything became clearer.
// this is enough.
server = new TcpListener(IPAddress.Any, port);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question