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 Bry_Perk · May 28, 2018 at 03:27 AM · networkingmultiplayerasynchronousudp

UdpClient EndRecieve recieves a list of null bytes

I'm writing a network manager for communicating between my server and client, but I'm receiving an odd issue when I attempted to start receiving asynchronously. That is, when I call EndRecieve on my UdpClient, 70-99.99% of the byte[] i get back are the correct length, but full of completely null bytes. Occasionally I will receive a proper message back from the server, but it is seemingly at random. I have triple checked that the server is sending the bytes properly, and have determined that it is indeed the client that is having the issue.

Here is my NetworkManager class as it is now:

 using System;
 using System.Net;
 using System.Net.Sockets;
 using Messaging;
 
 namespace Network
 {
 
     public abstract class NetworkManager : IDisposable
     {
         private IPEndPoint serverEndpoint;
         private static UdpClient clientUdp;
 
         public NetworkManager(string serverIP, int serverPort)
         {
             clientUdp = new UdpClient();
             clientUdp.Client.ReceiveTimeout = 5000;
             serverEndpoint = new IPEndPoint(IPAddress.Parse(serverIP), serverPort);
 
             StartRecieve();
         }
 
         public void StartRecieve()
         {
             clientUdp.BeginReceive(new AsyncCallback(OnUDPRecieve), clientUdp);
         }
 
         protected void OnUDPRecieve(IAsyncResult result)
         {
             UdpClient socket = result.AsyncState as UdpClient;
 
             IPEndPoint source = new IPEndPoint(0, 0);
 
             byte[] info = socket.EndReceive(result, ref source);
 
             ManageResults(info);
 
             socket.BeginReceive(new AsyncCallback(OnUDPRecieve), socket);
         }
 
         protected abstract void ManageResults(byte[] info);
 
 
         public void SendUDP(Message m)
         {
             byte[] bytes = m.GetBytes();
             clientUdp.Send(bytes, bytes.Length, serverEndpoint);
         }
 
         public virtual void Dispose()
         {
             if (clientUdp != null) clientUdp.Close();
         }
     }
 }
 

And here is what I will generally get on my log output: alt text

The first line in the log is the null result I'm talking about (The first value is the x value extracted, the second is the hex of the byte[] and the final value is the username, which is empty)

The other lines are the occasional time that I receive actual information.

I have absolutely no idea why this is happening. I've tried putting the receiving on a dedicated thread, but that resulted in not receiving any bytes at all. I read in a comment deep in a thread somewhere that it might be a bug with Mono, but even if that is what is is, I'm not sure what else I would do in this situation.

Does anybody have a solution?

agggggg.png (23.5 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

0 Replies

· Add your reply
  • Sort: 

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

167 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 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

Unity networking tutorial? 6 Answers

Does Unity Support TCP or only UDP? 0 Answers

UDP Server Or Master Server 1 Answer

Asynchronous Game server 2 Answers

What properties from a HLAPI connection can be used to create a LLAPI connection? 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