Sorry for not contributing here properly,
It feels like you've got some misconception.
You do understand that the port is only a gateway between connecting sockets, ports are assigned like numbers on a page, without the port or page number, you can send data to an IP or browse through a book but not find what you're looking for. If you've got the page number you can get back to where you were, if you've got the port number the communication can continue.
Or like intergalactic space travel, you could know where another galaxy is location, but without a wormhole between the two locations well then you've got no port. lol
So I believe you confused ports with something else..
Perhaps the structure of communication packets between sockets.
Say you've got your client<>server connection setup. 3 clients are connected to 1 server. The 1 server has 3 socket IDs which it collected as the clients connected 1 by 1 since GMS isn't multithreaded it'll deal with clients one at a time.
Each client has a different socket ID, starting at 0 or 1 I believe, the server doesn't store it automatically, you'd put it in a list for later reference/use.
The clients have 1 ID for the server, which is probably 0 or 1 as well.. it simply increments but I'm sure there's more data behind it in the metacode of GM.
Connection is up, now what ?
we play with scenarios, what usually comes first ? registration, login, character creation, verification, that sorta stuff, you've also got movement, loading other player movement, accessing inventory, pretty much everything. You could also, btw retrieve a list from the server of IP
ORTs of other connected client/players and communicate with them directly, which is known as PeerToPeer. It's just a different hierarchy of data flow.
My approach to handling these different scenarios was thinking of it as a multidimensional array, hierarchy, or switch statements within switch statements, by that I mean the absolute first thing that happens when I handle networking is setting up the server, connecting to it, then the player clicks register and sends a network packet to the server containing the integer value "0", followed by a string "bob2023"(usn) followed by a string "39fj38j4f"(psw) some other things also occur like "remember password" will be a boolean that's value is stored client/player side in a .ini file or something, since it's unnecessary for the server to remember that information for the player. The server receives the socket ID on the async data event in the relevant DS_MAP? you then as in the code you posted, check to see the event type, and then receive the packets one at a time. The server will receive the int 0, the usn and psw and compute that, ensuring it passes filters and rules, the server still having the socket_id of the client, sends back a packet to the client with the int "0", the clients switch statement knows 0 represents registration stuff, the server in the next line of code sends the int 1, or int 0 and sends the packet, so client knows that 0 means registration, and that the data that follows will be relevant to registration, the client expects either a 0 or a 1 in the switch statement, or if statement.. 0, 0 means it's a registration event and the registration attempt was a failure, 0, 1 means it's a registration event and it was a success. So the user has registered and can now login.
The server would add the registration details to a data structure and store it immediately or later on to it's database.
The client then clicks login and sends the int 1 , string "bob2023" and string " 39fijieji" to the server, the server knows that 0 means register, 1 means login, this is a 1 so the following data in order will be a username and password, read it, compute it and respond accordingly.
I've heard that it's good practice to use constants for these defining values, alternatively you can be an idiot like me and not do that until eventually you've got 30-40 primary values coming through and it gets confusing(oh it helps to document what they all mean for quicker communication).
Right, but the reason people use integers instead of strings where "0" would mean "Register_event" and "1" "Login_event" is due to bandwidth, and a whole lot of other nonsense.
I hope I clarified a thing or two. It's quite a long read but I tried to keep it somewhat simple but still valuable. Let me know if it's jargon.