- Home /
 
UNET Network Discovery sends data with extra characters
So I am making a game with a custom script inherited from the Network Discovery component. In this script I am setting the broadcastData in LateUpdate on the server, and this process returns the expected length for the string. However, when I receive the data in OnReceivedBroadcast on the client, the string returns an extremely high length. I've tried using string.Trim() to remove any white-space characters, but that didn't seem to help. I know the UNET system is outdated, but could anyone help me figure out what's going wrong?
The method called in LateUpdate:
 //Update the data to reflect changes to the game and what is being broadcasted.
     public void UpdateBroadcastJoinInfo()
     {
         JoinGameInformation joinGameInfo = new JoinGameInformation();
 
         joinGameInfo.inSetupPhase = _gameSMan.phase == GamePhase.Setup;
         joinGameInfo.playersCount = _gameSMan.players.Count;
         joinGameInfo.filledPlayers = _gameSMan.playerConnectionObjects.Count;
         joinGameInfo.gameName = _gameCMan.beginGameInfo.gameName;
         joinGameInfo.hasPassword = _gameCMan.beginGameInfo.joinPassword != "";
 
         broadcastData = joinGameInfo.ToString();
 
         Debug.Log("The broadcastData is " + broadcastData);
         Debug.Log("The length of broadcastData is " + broadcastData.Length);
     }
 
               The OnReceivedBroadcast method:
 public override void OnReceivedBroadcast(string fromAddress, string data)
     {
         base.OnReceivedBroadcast(fromAddress, data);
 
         Debug.Log("The received data is " + data);
         Debug.Log("The length of data is " + data.Length);
 
         JoinGameInformation joinGameInfo = JoinGameInformation.Parse(data);
         joinGameInfo.ipAddress = GBLibrary.GetSubstringFromString(fromAddress, 3, ':');
         string portSubstring = GBLibrary.GetSubstringFromString(fromAddress, 4, ':');
         int parsedPortInt = 0;
         bool canParsePortInt = int.TryParse(portSubstring, out parsedPortInt);
         joinGameInfo.port = parsedPortInt;
 
         //If the given data was able to be parsed and is not the same as an empty game...
         if (!joinGameInfo.IsSameGameAs(JoinGameInformation.Empty))
         {
             //Once the info has been recieved and interpreted, either add a new LifetimedJoinGameInfo
             //or update an existing one so that the lifetime is set to the maximum.
             LifetimedJoinGameInfo lJoinGameInfo = lifetimedJoinGameInfos.Find(x => x.joinGameInfo.IsSameGameAs(joinGameInfo));
             if (lJoinGameInfo != null)
             {
                 lJoinGameInfo.joinGameInfo = joinGameInfo;
                 lJoinGameInfo.life = joinInfoLifetime;
             }
             else
             {
                 lifetimedJoinGameInfos.Add(new LifetimedJoinGameInfo(joinInfoLifetime, joinGameInfo));
             }
 
             if (onJoinGameInfoFound != null) onJoinGameInfoFound(joinGameInfo);
         }
     }
 
               The broadcast data on the server (the expected result): 
The received data on the client (which should be exactly the same as the broadcast data): 
Your answer
 
             Follow this Question
Related Questions
UNet - Connecting and Testing a 'choose your character' scenario 0 Answers
hi i need help with code 1 Answer
How Client send info to Host in Unity Multiplayer 0 Answers
Photon OnPhotonPlayerDisconnected Works For Only Master Client 0 Answers
Photon network won't join random room with a custom property 0 Answers