Allow only one application running at same time?

I’m adding multiplay feature
I want to prevent people launch multiple client to connect game server
(or launch multiple listen server, since it will cause application crash

how to make user can only run one application at same time?

Validate each user on the server? Don’t connect a userid if they are already playing a game.
You can’t control the user but you can control the server.

If it’s multiplayer you have some form of identification that you can use. You’ve got the IP address at the very least. But you should have a username, id etc.

Why would your app crash if a client launches multiple instances of the app? You would have to be relying on unique IP addresses (or similar) for this to cause a crash. And if you were that’s an easy error to check.

Edit: All of that being said, It might be possible. But it’s probably not an everyday feature and you may have to implement this on windows, mac and linux specifically. I suppose some games don’t let you open multiple instances, they just maximize the (already running) game when you try to. So it should be possible. My answer was mainly concerned with your concern for crashing, which shouldn’t happen with a robust implementation.

I’m just want to make user can only run one application at same time

of course I know there’s many way to validate user
the problem is the socket library is a DLL extension

I don’t want to risk or take time to rewrite extension
the easiest way just make user can run one game at time (like many other video game)

If you know what is cousing the crash you can use try-catch, like if app is binding to alredy used port or something. Second idea is to use file lock.

I think the best way is the PORT.

If the port is taken (server or client doesn’t matter as long as they use a different port) it means something it is using it already (most likely the same application and so this is the second instance), so I would show a message like "Port already taken. You can only run a single instance of " and quit.

Could it be?