Jump to content
  • Advertisement
Sign in to follow this  

Client connecting to remote server(not localhost)

This topic is 2305 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

So I've managed to create UDP server and client but I have no idea how to put the server on some remote hosting in the network. I found some free hosting here for example: http://www.000webhost.com/ . And how do I make my server run there? Does anyone know some step by step guide on setting up your server on other machine than your localhost? Becosue I'm totally confused here and would be very grateful for help!

Share this post

Link to post
Share on other sites
Theoretically, you can connect using the public IP, aka the IP allocated to you by your internet service provider.

Google 'MyIP'. Note that your IP will change regularly, unless it is a static IP which is unlikely.

hosting sites are usually registered with DNS services, so you can look up the actual address of say, "mymatchmakingservice.com", which will return you an IP for your matchmaking queries.

There are some intricacies using public IPs with hosts behind a firewall. Usually, you will need to forward ports, so that the port of your public IP is the same as the port of your private IP that your game host listens to.

Secondly, your firewall might prevent external queries to come through unless the port is specifically enabled to accept external queries. Often, the connection is initiated by your computer to the outside world (think internet browser queries). Running a game server, it is the other way round, where the outside world tries to connect to you. So it is a security issue.

What matchmaking services often do is act as a bridge between a client and a game server. Since the game server <-> matchmaking service link is already established and secured (hopefully), when a client tries to connect to a game server, the matchmaking service will forward the client address to the game server, so that the game server can open the link and allow the client to communicate with him.


As you can see, NAT punchthrough can get quite complicated.

Anyway, taking the simple approach first. Take Minecraft / simple indie multiplayer games with no matchmaking services.

Say you are located behind a router.

your current public IP (the internet IP that your ISP gave you, at the front of the router) is

Your computer hosting the server, connected to the router, has private IP (it's an IP allocated by the router to your computer, usually via DHCP).

You host your game on port 27015 (for example, that's the default host port used by Team Fortress 2).

The game's private address is therefore You can use that address to create a game on LAN, aka a private network.

However, if you do not forward the port, the router will allocate an arbitrary port for the public IP. Your public address for your game might be

Forwarding port 27015 would mean your internet IP would then be So to have people connect to your game server, they would only need to know your public IP ( And they can start sending requests to

Using a matchmaking service, it means that forwarding ports is not a pre-requisite. When you start a host, you will register your game session with the matchmaking service. Thus the matchmaking now knows your public game address whatever it may be ( Then when a client queries for a game, the matchmaking service can return that address to the client. Then the client can connect to it directly.

As for matchaking service providers, I don't know. I use PSN, XBL, and steamworks which do the dirty work for me. Edited by papalazaru

Share this post

Link to post
Share on other sites

#include <windows.h>
#include <wininet.h>
#pragma comment(lib, "wininet")
int main()
HINTERNET hInternet, hFile;
DWORD rSize;
static char buffer[64];
hFile = InternetOpenUrl(hInternet, "http://automation.whatismyip.com/n09230945.asp", NULL, 0, INTERNET_FLAG_RELOAD, 0);
InternetReadFile(hFile, &buffer, sizeof(buffer), &rSize);
buffer[rSize] = '\0';
MessageBoxA(0, buffer, "", MB_OK);

Then your friends need to know the IP, and the port the game uses.

On the server router, you need to forward the port, and open the port.

Not a 100% sure that method will give you the actual public address (when I tried it, it returned something weird).

Anyway, have a play with that. Or type 'my ip' in google. Edited by papalazaru

Share this post

Link to post
Share on other sites
thanks a lot again! I have some other tasks to complete before I'll be moving server on some hosting but I'll surely find your advices useful and appreciate your help! I hope I'll be able to do that eventually ^^

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!