예제 #1
0
    // Use this for initialization
    void Start()
    {
        qrData     = new QRTrackerData();
        qrPosition = new Vector3();

        pthread        = new Thread(new ThreadStart(SocRecv));
        recv           = true;
        isDataFresh    = false;
        lastUpdateTime = Time.time;
        pthread.Start();
    }
예제 #2
0
    void SocRecv()
    {
        soc = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
        byte[]     buf              = new byte[1024];
        IPEndPoint LocalIpEndPoint  = new IPEndPoint(IPAddress.Any, 8000);
        IPEndPoint RemoteIpEndPoint = new IPEndPoint(IPAddress.Parse("192.168.1.42"), 8000);

        soc.Bind(LocalIpEndPoint);

        Debug.Log("test3");

        while (recv)
        {
            try
            {
                soc.Receive(buf);

                lock (lockObject)
                {
                    string jsonString = Encoding.ASCII.GetString(buf);
                    Debug.Log(jsonString);
                    jsonString  = jsonString.Substring(0, jsonString.IndexOf('}') + 1);
                    qrData      = JsonUtility.FromJson <QRTrackerData>(jsonString);
                    isDataFresh = true;
                }
                Debug.Log("decoded");
            }
            catch (Exception e)
            {
                Debug.LogError(e.ToString());
            }
        }


        soc.Close();
    }