Welcome to PlagueFest.com! Log in or Sign up to interact with the Plague Fest community.
  1. Welcome Guest! to interact with the community and gain access to all the site's features.

Freaking networks, how do they work!?

Discussion in Networking started by Luffaren, May 8, 2015

  1. Feb 24, 2011
    Posts
    I'm not sure if this would fit better under the "Programming" section or not, but i'll just put it here since it's a network-related issue.

    BACKGROUND:
    I am implementing a network feature for my little 2D game engine thingie. The goal is to make it as easy/safe to use as possible for end users/devs.
    In the end i just wanna be able to host directly from the application as for letting other clients join in to play and have fun.
    Since it's a game engine which requires speed in the network i'm doing it all in UDP.

    RUNDOWN:
    I've already made a Net class in the engine, and things are working fine when testing locally.
    This is what's going down when establishing a connection:
    - HOST starts hosting
    - HOST is waiting for CLIENT to connect
    - CLIENT starts connecting (sending a request to connect)
    - CLIENT is waiting for HOST to "accept" (if HOST doesn't answer within 5 seconds a timeout error will occur)
    - HOST receives the request from CLIENT
    - HOST accepts the request from CLIENT
    - HOST sends an "accept" message to CLIENT
    - CLIENT receives the accept message
    - CLIENT and HOST can now play and frolick in the flowery fields with eachother
    - SUCCESS!


    Things are working out perfectly locally (same pc, 2 applications running), as i've also confirmed that the constant sending/receiving works by updating player positions.

    THE PROBLEM:
    The issue begins when trying to establish a connection between me and another person (from another country).
    This is what's going down when trying to establish a connection (im the host):
    - HOST starts hosting
    - HOST is waiting for CLIENT to connect
    - CLIENT starts connecting (sending a request to connect)
    - CLIENT is waiting for HOST to "accept" (if HOST doesn't answer within 5 seconds a timeout error will occur)
    - HOST receives the request from CLIENT
    - HOST accepts the request from CLIENT
    - HOST sends an "accept" message to CLIENT
    - XXXXXXXXXXXXXXXXXXXX
    - CLIENT times out while waiting for the accept message (never seems to receive it)
    - FAILURE!

    I've confirmed that the IP is correct on all clients that i've tested with (i print out the IP just to make sure it's correct).
    I've port forwarded on my end, the clients haven't, and i really don't want every single client having to do that. Look at CS:S for an example, who the heck needs to port forward as a client? The host should need to do that AT MOST.
    When CLIENT sends a request to connect, it includes an available port from their side (the client checks for an available "receiving" port before attempting to connect) so the host knows what IP/port to connect to.

    I have no clue what i'm doing wrong. Does every single dingle client need to open ports on their end? In that case, how the heck does CS:S/any other multiplayer game do it?
    Does it make a difference if i do TCP instead of UDP? I haven't tried it yet but i'm considering it due to desperation, even if it might mean going a bit slower.

    I am going generally insane over this, is there a network magician out there who wouldn't mind sparing a few words of wisdom?
  2. Jun 11, 2012
    Posts
    Oh yeah sorry I didn't reply, got busy somewhere else.

    Yes to the port forwarding, if you are behind a router and you are trying to get others to connect to your machine behind that same router, you need to forward. Simply because the router doesn't know how the connection is for and the client only sends IP:razz:ort where IP is your external IP. You can use UPnP but I've never done such thing, it can allow you to auto forward connection with minimal headache.

    TCP and UDP are not your root cause problem, they are simply message handling protocols. You will run to the same issue with UDP, TCP, or Both.

    If you are server and want to connect to someone else, you have to make sure all the port you are using are forwarded, you can use a blanket forward of ports like 32000 to 50000. However this is terrible because you are leaving a large portion of your port open. Same vice versa.

    Try reading on UPnP and check out this search.
    https://www.google.ca/search?q=upnp...ourceid=chrome&es_sm=119&ie=UTF-8#q=upnp java
  3. Feb 24, 2011
    Posts
    So multiplayer game like CS:S uses UPnP? Is it just a must for these kinds of situations?
    This just became a terrible headache, blargh!

    Also a sidenote/question. Right now the host has ONE receiving thread for itself and ONE sending thread for EACH client. Is this good practice, or do i need to have ONE receiving thread for EACH client AND ONE sending thread for EACH client?
    Caps lock is the best!
  4. Jun 11, 2012
    Posts
    It used to be that if you were hosting a game, you needed to open up all the ports. Halo 3 on the X360 had that issue when it launch. Same with torrents too.
  5. Feb 24, 2011
    Posts
    I'm alright with the host having to port forward, but not having every single client/end-user doing it.
    I'm looking at this java UnPn GIT project thing, but it's freaking huge! Like 10 times bigger than my entire project, i don't want to implement this external thing.
    I'm frantically looking for something else. Something smaller/easier to implement in order to port-forward through Java, but things are looking kinda dark.

    Another question:
    Doesn't establishing a connection between 2 places with TCP do something special?
    Sending raw UDP packets might not work since there's no "real connection" going on, but what about doing the entire TCP/accept thing?
    Luffaren, May 8, 2015 Last edited by Luffaren, May 8, 2015
  6. Mar 20, 2011
    Posts
    UPnP is the devil though THE DEVIL!