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 /
  • Help Room /
avatar image
0
Question by pgbarber · Oct 19, 2017 at 05:34 PM · networkinglanbroadcast

Network Discovery - client not receiving broadcast

I'm using Network Discovery for Server/Clients.


I have a simple UI that allows the user to select whether they are the server or client, which then adds the correct prefab to the scene. Other than Use Network Manager and Show GUI set to false, all other settings are default.


I tried running the Broadcast example project and the client also did not receive broadcasts. I'm running unity 2017.1.0f3.


The computers are connected using ethernet cables and a Netgear router, all running Windows 10.


Server:

 [AddComponentMenu( "Networking/NetServer" )]
 public class NetServer : NetworkDiscovery
 {
     void Start()
     {
         Application.runInBackground = true;
         StartServer();
     }

     //Call to create a server
     public void StartServer()
     {
         int serverPort = CreateServer();
         if( serverPort != -1 )
         {
             Debug.Log( "Server created on port : " + serverPort );
             broadcastData = serverPort.ToString();
             Initialize();
             StartAsServer();
         }
         else
         {
             Debug.Log( "Failed to create Server" );
         }
     }

     int minPort = 10000;
     int maxPort = 10010;
     int defaultPort = 10000;

     //Creates a server then returns the port the server is created with. Returns -1 if server is not created
     private int CreateServer()
     {
         int serverPort = -1;
         //Connect to default port
         bool serverCreated = NetworkServer.Listen( defaultPort );
         if( serverCreated )
         {
             serverPort = defaultPort;
             Debug.Log( "Server Created with deafault port" );
         }
         else
         {
             Debug.Log( "Failed to create with the default port" );
             //Try to create server with other port from min to max except the default port which we trid already
             for( int tempPort = minPort; tempPort <= maxPort; tempPort++ )
             {
                 //Skip the default port since we have already tried it
                 if( tempPort != defaultPort )
                 {
                     //Exit loop if successfully create a server
                     if( NetworkServer.Listen( tempPort ) )
                     {
                         serverPort = tempPort;
                         break;
                     }

                     //If this is the max port and server is not still created, show, failed to create server error
                     if( tempPort == maxPort )
                     {
                         Debug.LogError( "Failed to create server" );
                     }
                 }
             }
         }
         return serverPort;
     }
 }



Client:

 [AddComponentMenu("Networking/NetClient")]
 public class NetClient : NetworkDiscovery
 {
     void Start()
     {
         StartClient();
     }

     public void StartClient()
     {
         Initialize();
         StartAsClient();
     }

     public override void OnReceivedBroadcast( string fromAddress, string data )
     {
         Debug.Log( "Server Found: " + fromAddress + "\n" + "Data: " + data );
     }
 }



I've implemented Unity's network discovery class in my project to step through the code: https://bitbucket.org/Unity-Technol...Simple.cs?at=5.4&fileviewer=file-view-default


My client never receives a network event in the Update()

 networkEvent = NetworkTransport.ReceiveFromHost( m_HostId, out connectionId, out channelId, m_MsgInBuffer, k_MaxBroadcastMsgSize, out receivedSize, out error );


No error, just networkEvent is NetworkEventType.Nothing


Wireshark shows the broadcast coming through:

Src: 10.1.10.125, Dst: 10.1.255.255

Src Port: 49220, Dst Port: 47777

Length: 67


Client is 10.1.10.13

Server is 10.1.10.125


I noticed that in the NetworkDiscovery code, in StartAsServer() when calling:


NetworkTransport.Addhost() - the hostId returns is 1.


In StartAsClient() AddHost returns hostId 0.


In the Update(), ReceiveFromHost() takes the hostId.


I tried just setting it to 1 on the client and get the error: "host id out of bound id {1} max id should be greater 0 and less than {1}"


Not sure if the id's need to match or this is fine?

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

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Suraksha226 · Jul 22, 2019 at 05:27 AM

I removed the Update() function from NetworkDiscovery and replaced it with InvokeRepeating()

Comment
Add comment · 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
0

Answer by frgaj · Feb 01, 2018 at 09:23 PM

I think this is a bug with network discovery on windows, but I've found a workaround. I couldn't get it to work until I opened the same port with the UdpClient class and sent at least one byte of data to the broadcast address. After closing the port, the network discovery component started receiving the broadcasts from my other servers.

Comment
Add comment · 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

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

152 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Card Game using Network Manager 0 Answers

P2P Broadcasting issue 0 Answers

Unet with LAN and wifi Hotspot 3 Answers

How do I set an object to be used by a player, and a separate object for the second player via Multiplayer or Lan? 0 Answers

Is there any way to increase the rate of messages on Unet? 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