Jump to content

View more

Image of the Day

Boxes as reward for our ranking mode. ヾ(☆▽☆)
#indiedev #gamedev #gameart #screenshotsaturday https://t.co/ALF1InmM7K
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

Sign up now

Connecting without knowing servers IP

4: Adsense

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
3 replies to this topic

#1 maya18222   Members   


Posted 04 November 2012 - 08:19 AM

If I have 2 computers connected to the same router/switch, is it possible to write an application that can be running on both so that they can discover each other with only knowing a port number?

I havent really done much socket programming, but from what Ive done you usually have the server listening for connections on some port and the client is able to connect to the server by knowing the ip of the server and the appropiate port to send the request to.

How can I set it up so that clients can still connect to the server, .. but without knowing the servers IP?

Would it be a case of just repeatedley sending requests to a range of address you know the server could be on? or is there a better way?

#2 SiCrane   Moderators   


Posted 04 November 2012 - 08:42 AM

You could just use a broadcast address to discover each other.

#3 Angus Hollands   Members   


Posted 04 November 2012 - 01:14 PM

This is somewhat akin to matchmaking. The reason that large scale multiplayer games do not need to program the IP addresses of private hosts is because they use an intermediary. NAT punchthrough relies on this concept to permit the overcoming of NAT translation. The resultant idea is that you always have one intermediary who has a specific static address and port which remains open all of the time. To connect peers, the host may register themselves on this intermediary, and the client can access a host list from the intermediary to understand who to connect to.

#4 0BZEN   Members   


Posted 06 November 2012 - 06:51 AM

Broadcast only works for computers sharing the same subnet (LAN games).

Ohterwise you need an introducer / matchmaker. These usually comes in the for of a registered domain (for which you can find the IP via a DNS lookup). It doesn't need to be, your matchmaking server could just be some machine on the net with a static IP and opened port.

Each player hosting a game would register themselves with that matchmaking server. Typically, a new session host would register himself with the matchmaking server, which will give the server the host's public IP. Then it's just a matter of keeping that session host IP and host session properties stored away for the duration of the game.

Then anyone wanting to connect to that session host would query the matchmaking server. Then the server returns the address of the session host in the query response.

The second benefit of using a matchmaking server is that it can act as an introducer for NAT punch-through, which is necessary for enabling players being routers to connect to each other.

Without a matchmaking server, you cannot know the IP address of the host. the host has to discover its own public internet address, and somehow send his IP to the client, via IM, email, or some form of game invite.

Something like this, although I'm not entirely sure about its reliability.
[source lang="cpp"]#include <windows.h>#include <wininet.h>#pragma comment(lib, "wininet")void show_ip_address(){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);}[/source]

Edited by papalazaru, 06 November 2012 - 06:54 AM.

Everything is better with Metal.

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.