How do I connect a subdomain to a custom gameserver through DNS or some other means [closed]

So, me and a friend built a custom gameserver in java. This gameserver listens for HTTP and TCP messages from a specific ip / port given to it (Either localhost or the device's external IP address for port forwarding). Then, you can take that IP / Port combination and use it in the game, and it connects fine. The server works beautifully. The issue is, we want to setup a domain for the server. The virtual private server hosting the actual gameserver is a Google Cloud Virtual Machine. Im using Cloud DNS to connect my domains to the apache webservers on my VM.

I was wondering if theres a way to connect to my gameserver's IP and Port through a subdomain... such as gateway.gameserver.com

I tried using an SRV record, and plugging in my custom port + ip address, but it didnt respond.

I also tried just connecting to my domain (Which uses the same IP Address as my game server) and adding a port to the end, and that didnt work.

Im out of ideas.

I would really like to be able to connect to my custom gameserver through gateway.gameserver.com instead of 100.100.100.100:5000 or something.


Solution 1:

Domain names are mapped to IP addresses in DNS via A records. There is no place in A record to specify a port. Ports are usually totally separate from DNS, and depend on the particular application you use. So if the port you are using is non-standard for this particular kind of application, you always have to specify the port explicitly.

SRV records are not general-purpose, they are for use by specific applications that look particularly for this SRV record. If your gaming client supports SRV records, then you can set up a SRV record that will be used by it, otherwise SRV records are of no use to you.

However, if you have an A record (specifying IP address) that points to yourdomain.com, and if the game server runs on this very same IP address, you can definitely use yourdomain.com and the particular port number in your gaming client and it should work, unless the gaming client does not allow for free port selection and uses a fixed port. In this case you must run game server on that port and use only yourdomain.com in your gaming client.

If the domain name does not work in your gaming client, but the very same IP address that the domain name points to does, then either you have done something wrong or the gaming client does not support using domain names at all.