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 mgill4 · Jun 20, 2018 at 01:38 AM · networkingvrthreadingudp

UDP using HTC VIVE tracker

I'm working on sending the POSE of the HTC Vive tracker via UDP from a "client" PC Running the main VR experience and I want to update objects POSE on another computer (eventually phone) that has a simple app to engage with the player on the main PC. I'm using some code from Triad Semiconductors but having some trouble. Here is the "emitter" running on the PC:

 import triad_openvr
 import time
 import sys
 import struct
 import socket
 
 sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
 server_address = ('unitypc IPAddress', 8051) # will replace with cpu B IPaddress
 
 v = triad_openvr.triad_openvr()
 v.print_discovered_objects()
 
 if len(sys.argv) == 1:
     interval = 1/250
 elif len(sys.argv) == 2:
     interval = 1/float(sys.argv[0])
 else:
     print("Invalid number of arguments")
     interval = False
     
 if interval:
     while(True):
         start = time.time()
         txt = ""
         data =  v.devices["tracker_1"].get_pose_quaternion()
         sent = sock.sendto(struct.pack('d'*len(data), *data), server_address)
         #print('\r' + txt, end='')
         sleep_time = interval-(time.time()-start)
         if sleep_time>0:
             time.sleep(sleep_time)
 

And here is my code on my other computer I'm sending the data too:

 //The following code can be used to receive pose data from udp_emitter.py and use it to track an object in unity
 
 using UnityEngine;
 using System;
 using System.Net;
 using System.Net.Sockets;
 using System.Threading;
 
 public class udp_tracked_object : MonoBehaviour {
     Thread receiveThread;
     UdpClient client;
     private Double[] float_array;
     private int port = 8051;
 
     // Use this for initialization
     void Start () {
         float_array = new Double[7];
         receiveThread = new Thread(new ThreadStart(ReceiveData));
         receiveThread.IsBackground = true;
         receiveThread.Start();
     }
     
     // Update is called once per frame
     void Update () {
         transform.position = new Vector3((float) float_array[0], (float)float_array[1], (float)float_array[2]);
         transform.rotation = new Quaternion((float)float_array[3], (float)float_array[4], (float)float_array[5], (float)float_array[6]);
     }
 
     void OnApplicationQuit()
     {
         if (receiveThread != null)
             receiveThread.Abort();
         client.Close();
     }
 
     // receive thread
     private void ReceiveData()
     {
         port = 8051;
         client = new UdpClient(port);
         print("Starting Server");
         while (true)
         {
             try
             {
                 IPEndPoint anyIP = new IPEndPoint(IPAddress.Any, 0);
                 byte[] data = client.Receive(ref anyIP);
                 for (int i = 0; i < data.Length; i++)
                     float_array[i] = BitConverter.ToDouble(data, i * 8);
             }
             catch (Exception err)
             {
                 print(err.ToString());
             }
         }
     }
 
 }

I can send simple strings between two python programs already on the two computers so I'm stuck on what's going on with my UDP receiving end in unity. I don't think it's the firewall but I'm sending it all over my LAN wifi network at home. Thanks for the help in advance and I'm happy to clarify anything!

Comment
Add comment · Show 1
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 mgill4 · Jun 21, 2018 at 11:19 AM 0
Share

Solved the problem! Turns out to be a firewall issue. I was able to narrow it down to seeing where the program stopped or got hung up. I placed a print() right after the client.Receive() and it never got to it. Turns out - the receive function will sit there until something comes through but won't time out so back tracked it and found it was the firewall blocking the info.

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

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

Threading with UDPClient - Editor Freezing 2 Answers

Unity UDP freezes if disconnected from server 2 Answers

Multi-threading safely 1 Answer

Can I use coroutine to replicate .WaitOne() and .Set() behaviour? 1 Answer

How can I receive UDP packets into Unity Webplayer? 1 Answer


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