Ejemplo n.º 1
0
        /// <summary>
        /// get all data from discovery packet
        /// </summary>
        /// <param name="discoveryResponse">data from packet</param>
        /// <returns>true if </returns>
        public bool GetDiscoverData(out DiscoveryResponse discoveryResponse)
        {
            if (mPacketType == PacketType.PacketCommand)
            {
                byte[] portData = new byte[2];
                Array.Copy(mData, GetSize() - 2, portData, 0, 2);
                Array.Reverse(portData);
                discoveryResponse.Port = BitConverter.ToInt16(portData, 0);

                byte[] stringData = new byte[GetSize() - 10];
                Array.Copy(mData, 8, stringData, 0, GetSize() - 10);
                string data = System.Text.Encoding.Default.GetString(stringData);
                string[] splittedData = data.Split(',');

                discoveryResponse.HostName = splittedData[0].Trim();
                discoveryResponse.InfoText = splittedData[1].Trim();

                string camcount = splittedData[2].Trim();
                Regex pattern = new Regex("\\d*");
                Match camMatch = pattern.Match(camcount);

                if (camMatch.Success)
                {
                    camcount = camMatch.Groups[0].Value;
                    discoveryResponse.CameraCount = int.Parse(camcount);
                }
                else
                {
                    discoveryResponse.CameraCount = -1;
                }
                try
                {
                    discoveryResponse.IpAddress = "";
                    IPAddress[] adresses = System.Net.Dns.GetHostAddresses(discoveryResponse.HostName);
                    foreach(IPAddress ip in adresses)
                    {
                        if (ip.AddressFamily == AddressFamily.InterNetwork)
                        {
                            discoveryResponse.IpAddress = ip.ToString();
                            break;
                        }
                    }
                }
                catch
                {
                    discoveryResponse.IpAddress = "";

                    return false;
                }
                return true;
            }

            discoveryResponse.CameraCount = -1;
            discoveryResponse.HostName = "";
            discoveryResponse.InfoText = "";
            discoveryResponse.IpAddress = "";
            discoveryResponse.Port = -1;

            return false;
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Connect the specified pickedServer.
 /// </summary>
 /// <param name="pickedServer">Picked server.</param>
 /// <param name="udpPort">UDP port streaming should occur on.</param>
 /// <param name="stream6d"> if 6DOF data should be streamed.</param>
 /// <param name="stream3d"> if labeled markers should be streamed.</param>
 public bool Connect(DiscoveryResponse discoveryResponse, short udpPort, bool stream6d, bool stream3d)
 {
     if (!mProtocol.Connect(discoveryResponse, udpPort, RTProtocol.Constants.MAJOR_VERSION, RTProtocol.Constants.MINOR_VERSION))
     {
         if (!mProtocol.Connect(discoveryResponse, udpPort, LOWEST_SUPPORTED_UNITY_MAJOR_VERSION, LOWEST_SUPPORTED_UNITY_MINOR_VERSION))
         {
             Debug.Log("Error Creating Connection to server");
             return false;
         }
     }
     return ConnectStream(udpPort, StreamRate.RateAllFrames, stream6d, stream3d);
 }
 /// <summary>
 /// Create connection to server
 ///</summary>
 /// <param name="host">host detected via broadcast discovery</param>
 /// <param name="serverPortUDP">port to use if UDP socket is desired, set to 0 for automatic port selection</param>
 /// <param name="majorVersion">Major protocol version to use, default is latest</param>
 /// <param name="minorVersion">Minor protocol version to use, default is latest</param>
 /// <returns>true if connection was successful, otherwise false</returns>
 public bool Connect(DiscoveryResponse host, short serverPortUDP = -1, int majorVersion = Constants.MAJOR_VERSION, int minorVersion = Constants.MINOR_VERSION)
 {
     return Connect(host.IpAddress, serverPortUDP, majorVersion, minorVersion, host.Port);
 }
 /// <summary>
 /// Connect the specified pickedServer.
 /// </summary>
 /// <param name="pickedServer">Picked server.</param>
 /// <param name="udpPort">UDP port streaming should occur on.</param>
 /// <param name="stream6d"> if 6DOF data should be streamed.</param>
 /// <param name="stream3d"> if labeled markers should be streamed.</param>
 public bool Connect(DiscoveryResponse discoveryResponse, short udpPort, bool stream6d, bool stream3d)
 {
     if (mProtocol.Connect(discoveryResponse, udpPort))
     {
         return ConnectStream(udpPort, StreamRate.RateAllFrames, stream6d, stream3d);
     }
     Debug.Log("Error Creating Connection to server");
     return false;
 }