Thread: matchmaking connection of two addresses inside a NAT

  1. #1
    Registered User
    Join Date
    Jan 2005
    Posts
    108

    matchmaking connection of two addresses inside a NAT

    I'm trying to make a multiplayer matchmaking server for a game.. kind of like battle.net, for my game. The question is, if player A (behind a NAT) wants to connect to player B (the player who wishes to be the server, also behind a NAT), how can the matchmaking server tell B A's address?

    I mean, if they're all in the same network, all good, but yeah..

    thanks in advance

  2. #2
    Registered User
    Join Date
    Apr 2008
    Posts
    396
    Why do you need the IP address? this is kind of transparent for your application, as long as the connection is unique (clients have different ports, server too).
    If you do need the IP address, you may have to craft a network upper layer in which you embed the address. As you may know, for some specific protocols, NAT behaves differently (because those protocol would not work properly otherwise, like ftp, irc, ...), you coud also try to hack those, I think some of those 'special' packets contains the real address as additional data.

  3. #3
    Registered User
    Join Date
    Jan 2005
    Posts
    108
    Well, player A doesn't know player B's address.. so how would it connect?

    player A knows server C (the matchmaking server), and player B also knows player C. But if A and B is behind NAT, it's not gonna work is it?

    Hacking the protocol sounds a bit too far fetched for me.. Surely multiplayer games like starcraft and their matchmaking services (battle.net) are able to do this without too much complications?

  4. #4
    Registered User
    Join Date
    Apr 2008
    Posts
    396
    The gateway address (gateway which is also performing the NAT for requests from the private network) must be known, indeed, and this gateway, if properly configured, will forward the connection requests to the appropriate machine, it's its job. Now if you're speaking of a 'personal' network (i.e. using an ISP, with dynamic addressing), i don't have a miracle. The property of a server being that we know its (indirect or not) address and port as you said...

  5. #5
    Registered User
    Join Date
    Jan 2005
    Posts
    108
    Ah I see.. gateway address.. I'll look that up. So A can open a new connection to B using this gateway address?

    Isn't the gateway address some sort of ephemeral address though? What if B listens to a specific port only, can it still listen correctly?

  6. #6
    Registered User
    Join Date
    Apr 2008
    Posts
    396
    When client A tries to connect to server B, it sends its request to the gateway's address (of B's network), and this gateway will forward the request to B (the port for the gateway is the port of B), everything else will be managed automatically for your application, NAT is transparent for your application. The gateway address may be dynamic indeed (e.g. dsn box) but those equipments are rarely rebooted and this should be quite stable...
    I don't understand your last question, do you mean: what happens for B if the gateway address is modified? nothing particular, only clients have to be updated to connect to the new address.

  7. #7
    Registered User
    Join Date
    Jan 2005
    Posts
    108
    Sorry, I guess it wasn't clear.

    Client A -connects-> Matchmaker C [so C knows A's gateway address]
    Client B -connects-> Matchmaker C [same with B's gateway address]

    And then C sends B's (connecting) gateway address to A. Since B is the one that made the connection, B's gateway address would probably lead to some high-numbered port, say 32718

    However, B wants to host at port 1330. Can A get B:1330's gateway address? I hope that's makes it clear..

    p.s can B just host at port 32718, which is already being used for the connection?

  8. #8
    Registered User
    Join Date
    Apr 2008
    Posts
    396
    You can choose any free port you want for your socket, you get high numbered port when you let the kernel assign a free port for you. You need admin caps to use ports below 1024 though.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. variables when declared inside or outside a function
    By jas_atwal in forum C Programming
    Replies: 6
    Last Post: 12-14-2007, 02:42 PM
  2. Still battling with Copy Control
    By Mario F. in forum C++ Programming
    Replies: 9
    Last Post: 06-23-2006, 08:04 AM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  4. Headers that use each other
    By nickname_changed in forum C++ Programming
    Replies: 7
    Last Post: 10-03-2003, 04:25 AM