Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 samwood9797 · Sep 29, 2020 at 06:43 AM · .netthreadingsocketsudp

I cant read from the sockets properly - exception 0x80004005: An invalid argument was supplied

 private void ThreadMethod()
     {
         IPEndPoint RemoteIpEndPoint = new IPEndPoint(IPAddress.Any, 36864);
         UdpClient udp = new UdpClient();
         UnityEngine.Debug.Log("Entering Thread method...");
         while (true)
         {
             Byte[] receiveBytes = new byte[0];
             try
             {
                 // Set up receiver
                 receiveBytes = udp.Receive(ref RemoteIpEndPoint);
                 UnityEngine.Debug.Log("receiving bytes...");
             }
             catch (Exception err)
             {
                 UnityEngine.Debug.Log("UDP Client Socket Exception Error: " + err);
             }
             // Lock object so that multiple threads dont access data at the same time
             lock (lockObject)
             {
                 UnityEngine.Debug.Log("locked onto package...");
                 returnData = Encoding.ASCII.GetString(receiveBytes);
                 UnityEngine.Debug.Log("data is "+returnData.ToString());
                 handInfo items = JsonUtility.FromJson<handInfo>(returnData);
                 UnityEngine.Debug.Log("Array is "+items);
                 if (items != null) { translateData = true; }
                 else {UnityEngine.Debug.Log("Cannot reach data packages...");}
             }
         }
     }
 
unityconsole.png (128.7 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

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Bunny83 · Sep 29, 2020 at 08:13 AM

Remove this line:

 IPEndPoint RemoteIpEndPoint = new IPEndPoint(IPAddress.Any, 36864);

and add this one inside the while loop before your receive call:

 IPEndPoint RemoteIpEndPoint = new IPEndPoint(IPAddress.Any, 0);

This variable is meant to be set by the Receive method. The IP and port represents the sending port, not the receiving port. If you want to listen on port 0x9000 (36864) you should do

 UdpClient udp = new UdpClient(36864);

Keep in mind that the sending port nowadays can't really be choosen explicitly since almost everybody is behind a NAT router that exploits the source port for client identification. So the router will choose a random, currently unused source port in order to match a returned packet with the sending client.

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 samwood9797 · Sep 30, 2020 at 12:47 AM

Thanks for the reply, I have made those changes but now the program isn't moving past the receive method, returning the following exception:

UDP Client Socket Exception Error: System.Threading.ThreadAbortException at (wrapper managed-to-native) System.Net.Sockets.Socket.ReceiveFrom_internal(intptr,byte*,int,System.Net.Sockets.SocketFlags,System.Net.SocketAddress&,int&,bool)

I have attached the entire script attached to a cube gameObject (Move.cs) if needed. Cheers


movecs.zip (1.6 kB)
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

137 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

Related Questions

Program stopping at UDPClient.Receive() - timing issues? 1 Answer

Why breaks my Ethernet over USB (USB NCM) connection between HoloLens and PC? 0 Answers

UDP Sockets for networking, getting overloaded?? 0 Answers

UDP using HTC VIVE tracker 0 Answers

Socket exception: Access denied 3 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