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 phineliner · Nov 02, 2015 at 06:20 PM · networkingnetworkcrossplatformcross-platformbroadcast

UNET - Broadcast Data from Android changes when PC joins Network

Hi all,

I wrote a NetworkBroadcastSender and a NetworkBroadcastReceiver based on this. I'm currently inspecting the receiving data on different devices. I'm experiencing a weird behavior which I can not understand. If I'm running the BroadCastService between Windows only or Android only everything works as expected. If I'm running it on Android and Windows in the same network, the following happens:

alt text This is the log collected from the Windows Machine (* Delimiter)

I start the service on two Android devices (!!!!! and ????? Delimiters). The messages they sent and receive are displayed in log row 3 and 4. Those are the correct ones. Now that the windows machine joined the network (row 5 and 6), the received messages alter to the data displayed in the last two rows of the log image. As you can see, it seems that the delimiter of the windows machine seems to be appended to the data of the android devices (0*** after the !!!!! and the ?????). Exactly the same result is delivered in the android log:

alt text This is the log from the android device perspective.

I don't know why this is happening. I assume something withing the network is going wrong. I mean, how should the pc, which is the only one with the delimiters in code, affect the messages generated by the android devices who don't know about the delimiters? The android devices even keep sending the altered messages after the windows machine left the network again (until I restart the app on the android devices).

Does anyone have a clue of what is happening here?

Thanks, phineliner

P.S.: You may wonder why the pc log contains two broadcasts (row 5 and 6) from the windows machine: This is because there are two network cards on the win machine. Only one of these broadcasts will be forwarded to the android devices because of the subnet (this is intended). Thats why you see only one broadcast coming from the win machine in the android log.

screenshot-2015-11-02-10-44-12.png (48.9 kB)
log.jpg (71.3 kB)
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
Best Answer

Answer by phineliner · Nov 04, 2015 at 11:06 AM

I found out what was wrong (thanks to irwiss and Necromantic from the irc channel #unity3d-unet)! It was not a platform specific problem.

I was parsing the receiving broadcast data incorrectly. I did parse the whole msgBuffer, instead of only parsing a certain range (the receivedSize range). Thus, bufferData from previous messages would be appended to current messages, if the size of previous messages was bigger than the current one.

Refering to the used example mentioned above, you would need to extend the BytesToString method:

Previous:

 static string BytesToString(byte[] bytes)
     {
         char[] chars = new char[bytes.Length/ sizeof(char)];
         System.Buffer.BlockCopy(bytes, 0, chars, 0, bytes.Length);
         return new string(chars);
     }

Extended:

 static string BytesToString(byte[] bytes, int sizeToCopy = -1)
     {
         if (sizeToCopy < 0)
             sizeToCopy = bytes.Length;
 
         char[] chars = new char[sizeToCopy / sizeof(char)];
         System.Buffer.BlockCopy(bytes, 0, chars, 0, sizeToCopy);
         return new string(chars);
     }

In Addition one could ensure to Clear the buffer of exceeding bytes after calling GetBroadcastConnectionMessage(...) like so:

 Array.Clear(msgBuffer, receivedSize - 1, msgBuffer.Length - receivedSize);

Hope this helps someone else!

Cheers, phineliner

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Broadcast data not updating. 1 Answer

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

Help with player variables (prefab/network) 1 Answer

Bug in editor regarding networkspawn 0 Answers

Multiplayer desynchronize when grabbing an object by code. 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