Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Sebi16 · Aug 27, 2016 at 05:11 PM · networkingnetworkupdatebroadcast

Broadcast data not updating.

Hello!

I have a simple interface for a LAN Game: 1 textbox (to input host name), 1 host button (which modifies in a "STOP" button after "HOST" is clicked), 1 scroll list with all servers available and 1 join button. If i put "AAAA" name in textbox, press "HOST", after that press "STOP", the other devices will still see the server as available altough it is not (you can't connect to it).

     public void Host() {
         if (!isAlreadyHost) {
             if (hostName.text.Length != 0) {
                 isAlreadyHost = true;
                 discovery.StopBroadcast ();
                 discovery.Initialize ();
                 discovery.broadcastData = hostName.text;
                 discovery.StartAsServer ();
                 manager.StartHost ();
                 GameObject.Find ("Host").transform.GetChild (0).GetComponent<Text> ().text = "Stop";
         } else if (isAlreadyHost) {
             isAlreadyHost = false;
             GameObject.Find ("Host").transform.GetChild (0).GetComponent<Text> ().text = "Host";
             manager.StopHost ();
             discovery.StopBroadcast ();
             discovery.Initialize ();
             discovery.StartAsClient ();
         }        
     }

 void Start() {
        discovery.Initialize();
        discovery.StartAsClient();
 }


To update the list:

     public void updateListValues() {
         GameObject[] oldOptions = GameObject.FindGameObjectsWithTag ("option");
         foreach (GameObject oldOpt in oldOptions) {
             Destroy (oldOpt);
         }
         nr = discovery.broadcastsReceived.Count;
         if (nr > 0) {
             serverIps = new string[nr];
             serverNames = new string[nr];
             serverResults = new NetworkBroadcastResult[nr];
             discovery.broadcastsReceived.Keys.CopyTo (serverIps, 0);
             discovery.broadcastsReceived.Values.CopyTo (serverResults, 0);
             for (int i = 0; i < nr; i++) {
                 serverNames [i] = BytesToString (serverResults [i].broadcastData);
                 Button btnOption = Instantiate (option);
                 btnOption.transform.SetParent (gOparent.transform);
                 Vector3 optionPosition = new Vector3 (0.0f, -28.0f * i, 0.0f);
                 btnOption.transform.localPosition = optionPosition;
                 btnOption.transform.localScale = Vector3.one;
                 btnOption.GetComponent<RectTransform> ().sizeDelta = new Vector2 (0.0f, 30.0f);
                 GameObject optChild = btnOption.transform.GetChild(0).gameObject;
                 serverIps[i] = returnIP(serverIps[i]);
                 optChild.GetComponent<Text> ().text = serverNames [i];
                 btnOption.name = serverIps [i];
             }
         }

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by DiegoSLTS · Aug 28, 2016 at 12:36 AM

I'm reading the docs for NetworkDiscovery.broadcastsReceived and it never says how and when it's updated. I could be that it just stores every broadcast message received since Initialize runs.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Sebi16 · Aug 28, 2016 at 08:38 AM 0
Share

I don't think that's correct. If it would be like you say, than after I press "HOST" one more time with the name "BBBB", for example, I should have 2 items on the list, but ins$$anonymous$$d I've got only the BBBB, and the "AAAA" is gone.

Thanks anyway!

avatar image DiegoSLTS Sebi16 · Aug 28, 2016 at 02:16 PM 0
Share

Yes, what I said is probably incorrect. What I mean was that since the docs don't explain when and how that dictionary is updated, your assumption that it would contain only valid broadcasts could be wrong, and that you'll have to test different scenarios to see what's actually happening.

Also, maybe what I said isn't entirely wrong, the key to the dictionary is the address of the server, so when hosting a game with "AAAA" and then another with "BBBB" from the same server both broadcast messages use the same key, and the second one overrides the first one.

Broadcast messages are recevied in an async and probably not constant frequency, so you can't get something like a struct with all broadcast messages received in the current frame.

You might want to add some extra info in another dictionary of a similar struct with a timestamp, and update that timestamp every time you receive a message from the same address. When listing the current servers, check that timestamp against a threshold that you defined, so you can filter old messages received from servers that probably are not hosting.

Or since broadcastsReceived is not readonly you might be able to empty that every few seconds, so it's populated with recent broadcast messages only.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

UNET - How to listen for StopBroadcastDiscovery() to finish? And can buffer be changed while BroadcastDiscovery is running? 2 Answers

Load Previously Instantiated Network Objects 1 Answer

UNET - Broadcast Data from Android changes when PC joins Network 1 Answer

Since switching to using offline & online scenes in the NetworkManager, Clients will not sync (UNET) 0 Answers

Client disconnect due to error 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges