public void Disconnect()
 {
     _myThread.Abort();
     foreach (Type p in _subscribers)
     {
         _ws.Send(ROSBridgeMsg.UnSubscribe(GetMessageTopic(p)));
         Debug.Log("Sending " + ROSBridgeMsg.UnSubscribe(GetMessageTopic(p)));
     }
     foreach (Type p in _publishers)
     {
         _ws.Send(ROSBridgeMsg.UnAdvertise(GetMessageTopic(p)));
         Debug.Log("Sending " + ROSBridgeMsg.UnAdvertise(GetMessageTopic(p)));
     }
     _ws.Close();
 }
        /**
         * Removes a subscriber and disconnects him if the connection is already running.
         */
        public void RemoveSubscriber(Type subscriber)
        {
            if (!_subscribers.Contains(subscriber))
            {
                return;
            }

            _subscribers.Remove(subscriber);
            string topic = GetMessageTopic(subscriber);

            m_SubscribedTopics.Remove(topic);
            if (_running)
            {
                //since multiple subscribers can subscribe to same topic, only send unsubscribe if no more subscribers on this topic
                if (!m_SubscribedTopics.Contains(topic))
                {
                    Debug.Log("[ROS WEBSOCKET]Not subcribing anymore to " + topic);
                    _ws.Send(ROSBridgeMsg.UnSubscribe(topic));
                }
            }
        }
        /**
         * Disconnect from the remote ros environment.
         */
        public void Disconnect()
        {
            Debug.Log("[ROS WEBSOCKET] Disconnecting from ROS");
            _myThread.Abort();
            foreach (Type p in _subscribers)
            {
                string topic = GetMessageTopic(p);
                //remove this subscriber
                if (m_SubscribedTopics.Contains(topic))
                {
                    m_SubscribedTopics.Remove(topic);
                }
                //if no mo subscribers on this topic
                if (!m_SubscribedTopics.Contains(topic))
                {
                    Debug.Log("[ROS WEBSOCKET] not subscribing anymore to " + topic);
                    _ws.Send(ROSBridgeMsg.UnSubscribe(topic));
                }
            }
            foreach (Type p in _publishers)
            {
                string topic = GetMessageTopic(p);
                //remove this advertiser
                if (m_AnnouncedTopics.Contains(topic))
                {
                    m_AnnouncedTopics.Remove(topic);
                }

                //if no more advertiser on this topic
                if (!m_AnnouncedTopics.Contains(topic))
                {
                    Debug.Log("[ROS WEBSOCKET] not publishing on topic: " + topic);
                    _ws.Send(ROSBridgeMsg.UnAdvertise(topic));
                }
            }
            Debug.Log("[ROS WEBSOCKET] Closing websocket");
            _ws.Close();
            _running = false;
        }