Client connecting to remote server(not localhost)

Started by
4 comments, last by savail 11 years, 8 months ago
Hey,
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!
Advertisement
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.



http://www.brynosaur...pub/net/p2pnat/

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 43.12.154.3.

Your computer hosting the server, connected to the router, has private IP 192.168.1.3 (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 192.168.1.3:27015. 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 43.12.154.3:10048.

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

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 (43.12.154.3:10048). 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.

Everything is better with Metal.

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

#include <windows.h>
#include <wininet.h>
#pragma comment(lib, "wininet")
int main()
{
HINTERNET hInternet, hFile;
DWORD rSize;
static char buffer[64];
hInternet = InternetOpen(NULL, INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
hFile = InternetOpenUrl(hInternet, "http://automation.whatismyip.com/n09230945.asp", NULL, 0, INTERNET_FLAG_RELOAD, 0);
InternetReadFile(hFile, &buffer, sizeof(buffer), &rSize);
buffer[rSize] = '\0';
InternetCloseHandle(hFile);
InternetCloseHandle(hInternet);
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.

Everything is better with Metal.

*double post*

Everything is better with Metal.

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

This topic is closed to new replies.

Advertisement