Search Unity

Connecting to friend's host server with real IP addresses

Discussion in 'Multiplayer' started by chanfort, Jun 25, 2015.

  1. chanfort

    chanfort

    Joined:
    Dec 15, 2013
    Posts:
    641
    I noticed that there are plenty of tutorials how to set up a simple multiplayer game by using two windows (one with editor in game mode and another from built game mode). However, I got stuck at the start when I am trying to set up real connection with my friend, who uses computer from remote place (lets assume that my friend is not on the same LAN as me, e.g. lives somewhere in different country). More particular questions here are:

    1. How to properly find my and my friend's IP address and port which we could use for setting up host server on one of our computers? (I remember there can be also internal and external IP addresses).

    2. When we both find these IP addresses and ports, where we should enter them to properly set up master server and connection?
     
  2. MD_Reptile

    MD_Reptile

    Joined:
    Jan 19, 2012
    Posts:
    2,664
    Disclaimer: I'm still learning the networking too - and haven't tested online play only because I haven't progressed far enough yet.

    Anyway yeah just for testing and everything, you can direct connect through IP and port (assuming the appropriate port is forwarded on the firewall/router/modem) by just contacting someone, have them go to whatismyip.com and give you the public ip to them. Then either in your code decide a default port or enter it when starting a server through the gui or something - and hand the port and IP off when you start up the server, or connect the client.

    Now for release - that's a whole 'nother ball game! You better have some kind of master server who every player announces themselves to when they start a match. This way players can browse all active servers, through some gui magic. That is only the start though - you need NAT punch through to help players (especially mobile devices) get past firewalls/routers/gateways/modems or whatever other network issue is going on through the interwebs. This is possible (supposedly, I haven't tried) through the new service unity offers, which the name escapes me right now, but is free for us to test for the time being that helps with matchmaking.

    Hope I scratched the surface at least on those topics lol.

    Good luck!
     
  3. nmizrahi

    nmizrahi

    Joined:
    Aug 6, 2013
    Posts:
    45
    Hi guys, I'm struggling with this step right now. I'm trying to test using my own a friend's IP address but the editor tries and eventually does not connect. No errors. Any ideas?
     
  4. chanfort

    chanfort

    Joined:
    Dec 15, 2013
    Posts:
    641
    I started to use Unity's Matchmaker system and it seems to work well, no IPs needed to find or enter, matchmaker just finds the host room and the client can connect to it. Try it, I guess it's an easy way to get started.
     
  5. nmizrahi

    nmizrahi

    Joined:
    Aug 6, 2013
    Posts:
    45
    Thank you! That makes sense.
     
  6. nmizrahi

    nmizrahi

    Joined:
    Aug 6, 2013
    Posts:
    45
  7. chanfort

    chanfort

    Joined:
    Dec 15, 2013
    Posts:
    641
    I just used the cloud button in the Unity to connect project after I set up things in https://multiplayer.unity3d.com . But I did it long time ago, so it may work a bit differently now. Check the top lines here, it explains how to set up matchmaker: http://docs.unity3d.com/Manual/UNetInternetServicesOverview.html
     
  8. nmizrahi

    nmizrahi

    Joined:
    Aug 6, 2013
    Posts:
    45
    Ok, this is where I got hung up. In the video it shows him putting the product ID into a field in player setting instead of clicking on the cloud icon.

    The problem now is that the cloud icon does nothing. I have a services tab open, I"m logged into my account but nothing shows up. Do I have to be a pro user to use this service?

    Thank you!
     
  9. nmizrahi

    nmizrahi

    Joined:
    Aug 6, 2013
    Posts:
    45
    Nevermind my last reply. I did what you suggested and it worked with a couple little hang-ups.

    I'll list the steps here in case anyone else gets stuck.

    Go to Unity Editor and click the cloud button 4th from the upper right corner.

    This will bring up a services tab. I got stuck here because nothing was showing up (do I need to be a pro user, why is it blank?).

    I restarted unity and the services tab showed the projects I had set up in https://multiplayer.unity3d.com. (See below).

    I selected the organization (my username), my project name, and then my unity project Id.

    Thank you. Capture.PNG Capture2.PNG
     
  10. chanfort

    chanfort

    Joined:
    Dec 15, 2013
    Posts:
    641
    Great that you solved it. Now the most important thing is to check if it actually works between two separate computers, which are not on the same LAN (I would start with simplest player movement sync'ing to see if it works).
     
  11. slimabob

    slimabob

    Joined:
    Jul 7, 2013
    Posts:
    23
  12. marcolbx

    marcolbx

    Joined:
    Mar 4, 2019
    Posts:
    11
    Where you able to play with your friend using Unitys Matchmaking service?
     
  13. r31o

    r31o

    Joined:
    Jul 29, 2021
    Posts:
    460
    This thread is 7 years old :rolleyes:

    Anyway, you cant use it now, since its deprecated.
    A combination of lobby and relay is now the official way of doing it.
     
  14. marcolbx

    marcolbx

    Joined:
    Mar 4, 2019
    Posts:
    11
    Could you elaborate or refer me the link to the official way?
    Thanks
     
  15. r31o

    r31o

    Joined:
    Jul 29, 2021
    Posts:
    460