Depending on what language you are using, the answer can vary.
However, if you know any Java, or can at least get the gist of it, here's some old code I wrote to handle something like this.
https://github.com/TheDudeFromCI/WraithEngine/tree/5397e2cfd75c257e4d96d0fd6414e302ab22a69c/WraithEngine/src/wraith/library/Multiplayer
Basically it works like this. First, on your server, wherever it's being hosted, you have it open a socket on a port you choose. This should go on a dedicated thread, and handle ONLY this task. This should always be open, and listening for anyone trying to connect. When someone finally does connect, create a new dedicated thread, with a socket connecting to that client. When that client loses connection, (logs off, or force quits) kill the thread.
For the client, it's even simpler. Just have 1 thread, and have it try to connect to the server ip, (if you have only one server, hard code it in. If multiple, then you can have the player type it in.) And use the same port as you chose for the server. If a socket is able to be opened, connect, and that thread will be dedicated with chatting with the server. If you want to avoid delays in gameplay, this should not be your main thread, but in addition to. Then when a message is sent or received, pass it asynchronously to the main thread. To avoid stalling, make sure the main thread is never "waiting" on the server thread. (A waiting screen is fine for times where waiting is needed, because it doesn't cancel rendering events, or input events. So the program won't be marked as unresponsive.)
Now you should be able to handle an infinite number of new clients trying to connect.
Now, each thread is a seperate client. So keep these all in a list. Most likely in some kind of thread wrapper to handle easier packet sending and receiving. If you want some security, use a handshake packet. This means that the server "asks a question" sort of speak, and if the client doesn't answer, or answers incorrectly, it kicks them. Also, banned ips should be kicked before even the handshake.
Now, in your list of clients, wait for a match request to be called, however you want to do that, then take those clients that request it to be moved into a queue. Once you have enough players, start a match with that list of clients. When a packet is received, send it back to all other players in the list. For example, a player moves, a packet is sent, the server receives it, and sends it to all other players in the list, the render the move, and poof. If that's not fast enough, you can have players actually act like mini servers, and connect to each other fully. This will make pings twice as fast, but may be harder to detect hacking. So be careful.
Once the match is over, send a packet to the clients saying the match has ended, and make their clients render a game over screen when that packet is received.
I hope all of that makes sense.