Jump to content

  • Log In with Google      Sign In   
  • Create Account

Client connecting to remote server(not localhost)

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
5 replies to this topic

#1   Members   -  Reputation: 333


Posted 21 August 2012 - 03:55 PM

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!

#2   Crossbones+   -  Reputation: 2194


Posted 22 August 2012 - 03:49 AM

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, 22 August 2012 - 04:29 AM.

Everything is better with Metal.

#3   Members   -  Reputation: 333


Posted 22 August 2012 - 08:24 AM

Seems a bit complex but this info will surely come in handy, thanks a lot!

#4   Crossbones+   -  Reputation: 2194


Posted 22 August 2012 - 09:46 AM

#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, 22 August 2012 - 09:51 AM.

Everything is better with Metal.

#5   Crossbones+   -  Reputation: 2194


Posted 22 August 2012 - 09:47 AM

*double post*

Everything is better with Metal.

#6   Members   -  Reputation: 333


Posted 22 August 2012 - 11:39 AM

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 ^^

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.