Exemplo n.º 1
0
        // closes all sensor net servers
        private void CloseNetServers()
        {
            try
            {
                if (controlFrameServer != null)
                {
                    controlFrameServer.ReceivedMessage -= new ReceivedMessageEventHandler(ControlFrameReceived);
                    controlFrameServer.Close();
                    controlFrameServer     = null;
                    controlFrameCompressor = null;
                }

                if (colorFrameServer != null)
                {
                    colorFrameServer.Close();
                    colorFrameServer = null;
                }

                if (depthFrameServer != null)
                {
                    depthFrameServer.Close();
                    depthFrameServer     = null;
                    depthFrameCompressor = null;
                }

                if (infraredFrameServer != null)
                {
                    infraredFrameServer.Close();
                    infraredFrameServer = null;
                }

                if (bodyDataFrameServer != null)
                {
                    bodyDataFrameServer.Close();
                    bodyDataFrameServer = null;
                }

                if (bodyIndexFrameServer != null)
                {
                    bodyIndexFrameServer.Close();
                    bodyIndexFrameServer     = null;
                    bodyIndexFrameCompressor = null;
                }

                if (poseFrameServer != null)
                {
                    poseFrameServer.Close();
                    poseFrameServer = null;
                }

                if (depth2colorFrameServer != null)
                {
                    depth2colorFrameServer.Close();
                    depth2colorFrameServer = null;
                }

                if (color2depthFrameServer != null)
                {
                    color2depthFrameServer.Close();
                    color2depthFrameServer     = null;
                    color2depthFrameCompressor = null;
                }

                if (color2bodyIndexFrameServer != null)
                {
                    color2bodyIndexFrameServer.Close();
                    color2bodyIndexFrameServer     = null;
                    color2bodyIndexFrameCompressor = null;
                }

                if (serverStatusText)
                {
                    serverStatusText.text = "NetServer closed.";
                }
            }
            catch (System.Exception ex)
            {
                Debug.LogError("Error closing NetServer: " + ex.Message);
                Debug.Log(ex);

                if (serverStatusText)
                {
                    serverStatusText.text = string.Format("Error closing NetServer: {0}", ex.Message);
                }
            }
        }
Exemplo n.º 2
0
        // initializes the sensor net servers
        private void InitNetServers(KinectInterop.FrameSource dwFlags)
        {
            try
            {
                lastKeepAliveFrameTime = 0;
                lastSensorPoseStr      = string.Empty;
                int minPort = int.MaxValue, maxPort = int.MinValue;

                controlFrameServer = new TcpNetServer(baseListenPort + (int)NetMessageType.Control, "ControlServer", sbConsole);
                controlFrameServer.ReceivedMessage += new ReceivedMessageEventHandler(ControlFrameReceived);
                minPort = Mathf.Min(minPort, controlFrameServer.serverPort); maxPort = Mathf.Max(maxPort, controlFrameServer.serverPort);

                if (compressRawFrames)
                {
                    controlFrameCompressor = LZ4CompressorFactory.CreateNew();
                }

                if ((dwFlags & KinectInterop.FrameSource.TypeColor) != 0 && sensorData.colorImageTexture != null)
                {
                    colorFrameServer = new TcpNetServer(baseListenPort + (int)NetMessageType.Color, "ColorServer", sbConsole);
                    minPort          = Mathf.Min(minPort, colorFrameServer.serverPort); maxPort = Mathf.Max(maxPort, colorFrameServer.serverPort);
                }

                if ((dwFlags & KinectInterop.FrameSource.TypeDepth) != 0)
                {
                    depthFrameServer = new TcpNetServer(baseListenPort + (int)NetMessageType.Depth, "DepthServer", sbConsole);
                    minPort          = Mathf.Min(minPort, depthFrameServer.serverPort); maxPort = Mathf.Max(maxPort, depthFrameServer.serverPort);

                    if (compressRawFrames)
                    {
                        depthFrameCompressor = LZ4CompressorFactory.CreateNew();
                    }
                }

                if ((dwFlags & KinectInterop.FrameSource.TypeInfrared) != 0)
                {
                    infraredTex2d       = new Texture2D(sensorData.depthImageWidth, sensorData.depthImageHeight, TextureFormat.ARGB32, false);
                    infraredFrameServer = new TcpNetServer(baseListenPort + (int)NetMessageType.Infrared, "InfraredServer", sbConsole);
                    minPort             = Mathf.Min(minPort, infraredFrameServer.serverPort); maxPort = Mathf.Max(maxPort, infraredFrameServer.serverPort);
                }

                if ((dwFlags & KinectInterop.FrameSource.TypeBody) != 0)
                {
                    bodyDataFrameServer = new TcpNetServer(baseListenPort + (int)NetMessageType.BodyData, "BodyDataServer", sbConsole);
                    minPort             = Mathf.Min(minPort, bodyDataFrameServer.serverPort); maxPort = Mathf.Max(maxPort, bodyDataFrameServer.serverPort);
                }

                if ((dwFlags & KinectInterop.FrameSource.TypeBodyIndex) != 0 && serveBodyIndexFrames)
                {
                    bodyIndexFrameServer = new TcpNetServer(baseListenPort + (int)NetMessageType.BodyIndex, "BodyIndexServer", sbConsole);
                    minPort = Mathf.Min(minPort, bodyIndexFrameServer.serverPort); maxPort = Mathf.Max(maxPort, bodyIndexFrameServer.serverPort);

                    if (compressRawFrames)
                    {
                        bodyIndexFrameCompressor = LZ4CompressorFactory.CreateNew();
                    }
                }

                if ((dwFlags & KinectInterop.FrameSource.TypePose) != 0)
                {
                    poseFrameServer = new TcpNetServer(baseListenPort + (int)NetMessageType.Pose, "PoseServer", sbConsole);
                    minPort         = Mathf.Min(minPort, poseFrameServer.serverPort); maxPort = Mathf.Max(maxPort, poseFrameServer.serverPort);
                }

                if ((dwFlags & KinectInterop.FrameSource.TypeColor) != 0 && (dwFlags & KinectInterop.FrameSource.TypeDepth) != 0)
                {
                    depth2colorFrameServer = new TcpNetServer(baseListenPort + (int)NetMessageType.Depth2Color, "TColorServer", sbConsole);
                    minPort = Mathf.Min(minPort, depth2colorFrameServer.serverPort); maxPort = Mathf.Max(maxPort, depth2colorFrameServer.serverPort);
                }

                if ((dwFlags & KinectInterop.FrameSource.TypeColor) != 0 && (dwFlags & KinectInterop.FrameSource.TypeDepth) != 0)
                {
                    color2depthFrameServer = new TcpNetServer(baseListenPort + (int)NetMessageType.Color2Depth, "TDepthServer", sbConsole);
                    minPort = Mathf.Min(minPort, color2depthFrameServer.serverPort); maxPort = Mathf.Max(maxPort, color2depthFrameServer.serverPort);

                    if (compressRawFrames)
                    {
                        color2depthFrameCompressor = LZ4CompressorFactory.CreateNew();
                    }
                }

                if ((dwFlags & KinectInterop.FrameSource.TypeColor) != 0 && (dwFlags & KinectInterop.FrameSource.TypeDepth) != 0 && (dwFlags & KinectInterop.FrameSource.TypeBodyIndex) != 0)
                {
                    color2bodyIndexFrameServer = new TcpNetServer(baseListenPort + (int)NetMessageType.Color2BodyIndex, "TBodyIndex", sbConsole);
                    minPort = Mathf.Min(minPort, color2bodyIndexFrameServer.serverPort); maxPort = Mathf.Max(maxPort, color2bodyIndexFrameServer.serverPort);

                    if (compressRawFrames)
                    {
                        color2bodyIndexFrameCompressor = LZ4CompressorFactory.CreateNew();
                    }
                }

                if (serverStatusText)
                {
                    string localName = GetLocalNameOrIP();
                    serverStatusText.text = string.Format("NetServer listens on {0}:{1}-{2}", localName, minPort, maxPort);
                }
            }
            catch (System.Exception ex)
            {
                Debug.LogError("Error initing NetServer: " + ex.Message);
                Debug.Log(ex);

                if (serverStatusText)
                {
                    serverStatusText.text = string.Format("Error initing NetServer: {0}", ex.Message);
                }
            }
        }