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 savail   Members   -  Reputation: 333

Like
0Likes
Like

Posted 21 August 2012 - 03:55 PM

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!

Sponsor:

#2 0BZEN   Crossbones+   -  Reputation: 2013

Like
1Likes
Like

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.



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.

Edited by papalazaru, 22 August 2012 - 04:29 AM.

Everything is better with Metal.


#3 savail   Members   -  Reputation: 333

Like
0Likes
Like

Posted 22 August 2012 - 08:24 AM

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

#4 0BZEN   Crossbones+   -  Reputation: 2013

Like
1Likes
Like

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];
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.

Edited by papalazaru, 22 August 2012 - 09:51 AM.

Everything is better with Metal.


#5 0BZEN   Crossbones+   -  Reputation: 2013

Like
0Likes
Like

Posted 22 August 2012 - 09:47 AM

*double post*

Everything is better with Metal.


#6 savail   Members   -  Reputation: 333

Like
0Likes
Like

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.



PARTNERS