Search Unity

Question how can I make a script to determine the host address?

Discussion in 'Multiplayer' started by somedevelopergg, Sep 25, 2021.

  1. somedevelopergg

    somedevelopergg

    Joined:
    Oct 29, 2020
    Posts:
    25
    in the default mirror is the local host and the client connects only to it. how can i change this? it is clear that you need to write your own HUD manager, but I can't find anywhere how to make a working multiplayer, at least for a test with friends.
     
  2. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
  3. somedevelopergg

    somedevelopergg

    Joined:
    Oct 29, 2020
    Posts:
    25
    Thanks! But I have two more questions: is it only for local communication or can it work in the network as well? Is it suitable for primary tests?
     
  4. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    I think you're asking whether it works for only local network, or over the Internet. If you look at that documentation link, it says it uses broadcasts. Broadcasts aren't propagated by layer 3 devices, meaning they don't travel out into the Internet. For over the Internet, use a dedicated server that everyone connected to the Internet can connect to.
     
  5. somedevelopergg

    somedevelopergg

    Joined:
    Oct 29, 2020
    Posts:
    25
    so i cant do any host-client based game to play on the internet?
     
  6. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    Sure you can, but you need some server somewhere that can at least coordinate that communication. It can be a server you create and control, or it can be a 3rd party service.
     
  7. somedevelopergg

    somedevelopergg

    Joined:
    Oct 29, 2020
    Posts:
    25
    So in games like muck, there is a server that coordinates players? Can i just make a system that finds the IP of a host and displays it?
     
  8. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    The problem with just finding the IP of a host is almost everyone on the Internet is behind a NAT router. The host device has a private non-routable IP address, and the IP everyone else on the Internet sees is the IP of the router. When another device sends a client request to the router IP address, it has no idea what to do with it unless you've manually set up a port forwarding configuration on the router first. Google for Network Address Translation for more information on this topic.
     
    somedevelopergg likes this.
  9. somedevelopergg

    somedevelopergg

    Joined:
    Oct 29, 2020
    Posts:
    25
    that is, you can't just look at the ip and say? hmm ... I know there are some programs for creating a temporary server for playing on the network. can the unity work with them or you don’t know? probably it's better just so that one person from a group of friends could create a server and tell its IP to others .. oh, everything is so complicated ((
     
    Last edited: Oct 7, 2021
  10. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    Are you talking about over the internet or just on a local internet?

    Because if you're talking about over the internet, again your computer's IP address doesn't exist on the internet. Sharing your computer's IP address to someone else on the internet is pointless, because no one else's computers have any clue how to get to it. This is an IT issue, not a Unity issue.

    As far as what other software Unity can work with. Unity can work with any software, so long as you can find or write the API to talk to it.
     
    somedevelopergg likes this.
  11. somedevelopergg

    somedevelopergg

    Joined:
    Oct 29, 2020
    Posts:
    25
    So I need a server to be visible on the Internet? I just want to make it as simple as possible. if i need a server, can i just run the one on the computer?
     
  12. somedevelopergg

    somedevelopergg

    Joined:
    Oct 29, 2020
    Posts:
    25
    i kinda got it. sure it needs a server. but i just wanna ask one question: do cooperative games or games with rooms use servers that coordinates the clients?