/// <summary> /// Disconnect from the remote ros environment. /// </summary> public void Disconnect() { if (!this.IsConnected) { return; } // this.sendMsgThread.Abort(); this.isConnected = false; Thread.Sleep(15); foreach (var sub in this.subscribers) { this.webSocket.Send(ROSBridgeMsg.UnSubscribe(sub.Key.Topic)); } foreach (var pub in this.publishers) { this.webSocket.Send(ROSBridgeMsg.UnAdvertiseTopic(pub.Topic)); } foreach (var srv in this.serviceProviders) { this.webSocket.Send(ROSBridgeMsg.UnadvertiseService(srv.Key.Name)); } this.webSocket.Close(); this.msgQueue.Clear(); }
/// <summary> /// Remove a subscriber callback from this connection. /// </summary> /// <param name="subscriber"></param> public void Unsubscribe(ROSBridgeSubscriber subscriber) { if (subscriber == null) { return; } this.subscribers.Remove(subscriber); this.msgQueue.Remove(subscriber.Topic); if (this.IsConnected) { this.webSocket.Send(ROSBridgeMsg.UnSubscribe(subscriber.Topic)); } }