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(); }
/** * 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; }
/** * Removes a publisher from the connection. Disconnects the publisher if connection is already running. */ public void RemovePublisher(Type publisher) { if (!_publishers.Contains(publisher)) { return; } _publishers.Remove(publisher); //keep track of all publishers no matter if the topic string topic = GetMessageTopic(publisher); m_AnnouncedTopics.Remove(topic); if (_running) { //if we hvae no more publishers on this topic if (!m_AnnouncedTopics.Contains(topic)) { Debug.Log("[ROS WEBSOCKET] not announcing anymore on: " + topic); _ws.Send(ROSBridgeMsg.UnAdvertise(topic)); } } }