0

I have a server that i use to run game servers on for my friends and me, and some of the servers are "attack-able" (monsters can destroy our base) so i want the server to be shut down when not in use. Then i was wondering if there was a way to detect if there was an incoming signal (trying to connect to the server) on the given port, so the server can be turned on?

Raw question: Is there a way to detect, if someone is trying to send a message (or connect) through a specific port in c# (or another language better suited for this action)?

Dan Beaulieu
  • 19,406
  • 19
  • 101
  • 135
zzzbatmand
  • 17
  • 3

2 Answers2

0

Yes, you have to create a server to listen on that port. The problem you will face is that the server you create to detect incoming connections will need to be shut down so the game server can be turned on. They can't listen on the same port unless they're coded to work together and that likely isn't going to be the case with your game server.

squillman
  • 13,363
  • 3
  • 41
  • 60
0

If you want to see if there is any connections in use you can try to list all current TCP connections (assuming server using TCP) and find if there is any alive connection to specific port.

Resmon does this in his "Network" tab, so there must be a way to access it programmatically.

Here is answer describing how to get active TCP connections.

How can I get all the the active TCP connections using .NET Framework (no unmanaged PE import!)?

You probably should monitor server with some intervals because player might lose and reestablish connection, so sample it every 10 seconds or so and if there is no connection for more than few samples - shut down the server.

Community
  • 1
  • 1
Oleh Nechytailo
  • 2,155
  • 17
  • 26