Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

How to make a super simple network?

Discussion in 'Multiplayer' started by DarkDeivel, Nov 28, 2022.

  1. DarkDeivel

    DarkDeivel

    Joined:
    Aug 31, 2016
    Posts:
    127
    Hi all! How can I make a very simple network? I have an android application installed on several smartphones. I need to send a signal to other applications when I press one button in the application. I only need 1 function from the network.

    I have little experience with PUN, but it gives a delay, I need something as fast as possible. So that you can transmit a network signal via Bluetooth or Wifi. What solution is worth exploring for this? Thank you.
     
  2. RikuTheFuffs-U

    RikuTheFuffs-U

    Unity Technologies

    Joined:
    Feb 20, 2020
    Posts:
    440
    Hi @DarkDeivel , you can achieve it by connecting all the clients either through a dedicated server service (more expensive, but reliable), or through a Relay server + NAT punchthrough (cheaper, but cheateable).
    If the devices are all on the same local network, you can even use direct IP.

    Once they're connected, you can use a networking framework like Netcode For GameObjects to send messages across them.

    Does this answer your question?
     
    DarkDeivel likes this.
  3. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,350
  4. Punfish

    Punfish

    Joined:
    Dec 7, 2014
    Posts:
    389
    When you say, gives a delay, how long as you referring? There will always be some delay due to data traveling over the network.
     
  5. DarkDeivel

    DarkDeivel

    Joined:
    Aug 31, 2016
    Posts:
    127
    The question of cheating does not bother me in this matter. Thanks for the advice, I'll look into it.

    Interesting, I'll look into that, thanks a lot.

    Hello, I know, but the photon has more than it needs, because there is no direct connection.
     
    RikuTheFuffs likes this.
  6. Punfish

    Punfish

    Joined:
    Dec 7, 2014
    Posts:
    389
    Okay so you mean it's going through their relay.
    You're going to have a delay no matter what, which of course will be marginally higher if using a relay or dedicated server.

    If you want to connect to devices outside your network some sort of relay or NAT is going to be required.

    From your original message I got the impression you're open to other solutions. If you are looking to connect to devices on your own network consider giving FishNet a try. It has a network discovery addon just for this, which bypasses the need for a relay https://fish-networking.gitbook.io/docs/manual/general/add-ons
    FishNet can also use relays and dedicated servers of course.
     
    DarkDeivel likes this.
  7. DarkDeivel

    DarkDeivel

    Joined:
    Aug 31, 2016
    Posts:
    127
    The thing is, I'm a musician. I created a player in Unity that plays a metronome. Each musician has his own smartphone with headphones connected to it. I need one person to press the "PLAY" button and everyone else immediately starts the player. Therefore, the question of cheating does not bother me :) I need to send a signal to the rest of the players as quickly as possible, in total it turns out 1 function. But I also need it to be without the internet, because we may be in places where the internet connection is bad. Thank you for the proposed solutions, I will look at them and hope that something will suit my tasks.
     
  8. Punfish

    Punfish

    Joined:
    Dec 7, 2014
    Posts:
    389
    Are you trying to make it so each player gets the communication at the same time to equate fairness?
     
  9. DarkDeivel

    DarkDeivel

    Joined:
    Aug 31, 2016
    Posts:
    127
    As far as possible, I understand that this cannot be without delays, but it must be done as quickly as possible. I haven't studied the links they gave me yet, I'm waiting for the weekend.
     
  10. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,062
    In PUN, you can send an event to all players (including the sender) via the server (RaiseEvent has the target "all" in it's options). Means: The Photon Server is sending this to everyone at the same time.
    The issue is: When one player has loss or worse lag when the signal is sent, then this player will still be late.
    You'd have the same with a dedicated server or direct connections, unless you sync the time between the players and everyone starts playing at a specific synced timestamp.
     
    DarkDeivel likes this.
  11. DarkDeivel

    DarkDeivel

    Joined:
    Aug 31, 2016
    Posts:
    127
    Hello. The idea with a certain timestamp is cool and how did I not think of it before :oops:

    P.S. As far as I knew, it seems that Photon Bolt can do without the Internet?
     
  12. Punfish

    Punfish

    Joined:
    Dec 7, 2014
    Posts:
    389
    So you are trying to make it that all players get the message at the same time?
     
  13. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,062
    Sorry to say but we don't offer the LAN support anymore.
     
    DarkDeivel likes this.
  14. DarkDeivel

    DarkDeivel

    Joined:
    Aug 31, 2016
    Posts:
    127
    No, I'm not trying, a little delay is acceptable, but I liked tobiass' idea of the timestamp. In theory, with such ideas, the delay is no longer so critical.
     
  15. Punfish

    Punfish

    Joined:
    Dec 7, 2014
    Posts:
    389
    As a general rule when seeking help explain your desired outcome rather than asking help with a specific route to take. It's not uncommon that something can be done in an easier fashion but without knowing why/what you are ultimately after it's difficult to make suggestions.
     
  16. DarkDeivel

    DarkDeivel

    Joined:
    Aug 31, 2016
    Posts:
    127
    So the topic title says how to make a super simple network, this meant that someone would suggest the simplest asset in which you don’t have to write a bunch of code for one function, secondly, in post number 7 I wrote a situation for which I need a network.
     
  17. Punfish

    Punfish

    Joined:
    Dec 7, 2014
    Posts:
    389
    Well, without Internet is kind of the impossible, with the exception of LAN.

    I do think Fish-Networking can cover your needs; it's very flexible and does also offer LAN support.

    While I did read #7 I was not sure if your intentions were to have all OTHER players start at the same time, or the person pressing play + others to start at the same time. Either way, latency is going to be a factor no matter what.

    To give you an example of how you might do this in FishNet though ...
    Code (CSharp):
    1.  
    2. private const double PLAYER_DELAY = 0.3d; //Maximum delay to wait for all players to get packet.
    3.  
    4. public void OnClick_Play()
    5. {
    6.    ObserversPlay(TimeManager.Tick);
    7. }
    8. private IEnumerator XYZ(double wait)
    9. {
    10.    yield return new WaitForSeconds(wait);
    11.   PlayStuff();
    12. }
    13.  
    14. [ObserversRpc]
    15. private void ObserversPlay(uint tick)
    16. {
    17.     double timePassed = TimeManager.TimePassed(tick);
    18.     double waitRemaining = Mathf.Max(0d, PLAYER_DELAY - timePassed);
    19.     StartCoroutine(XYZ(waitRemaining));
    20. }
    You send the 'tick' which is aligned on all players. Using FishNet API 'TimePassed' you get the time it took to recv the packet. Then all players wait the remaining time of 'PLAYER_DELAY - timePassed'. They will all start at the same time, including host.
     
    DarkDeivel likes this.
  18. DarkDeivel

    DarkDeivel

    Joined:
    Aug 31, 2016
    Posts:
    127
    Hello. This helped me, I really achieved the perfect synchronization for me in the tests. As for the LAN, that's enough. I distributed a Wi-Fi access point with one phone, and connected with the other by specifying the Client Address IP of the main phone. Thank you.
     
    Last edited: Dec 3, 2022
    MrBigly and Punfish like this.