From 41df41b1c95e1075fe8b6ebfc41eb4f033191f2e Mon Sep 17 00:00:00 2001 From: wallarelvo Date: Thu, 4 Feb 2016 04:13:26 +0800 Subject: [PATCH] Trying to make the bloody thing faster --- launch/example.launch | 14 +++++++------- src/client/client_node.py | 4 +--- src/client/connection.py | 8 ++++---- src/client/publishermanager.py | 5 ++--- src/server/server_node.py | 4 ++-- src/server/ws.py | 1 + 6 files changed, 17 insertions(+), 19 deletions(-) diff --git a/launch/example.launch b/launch/example.launch index af50792..6644faf 100644 --- a/launch/example.launch +++ b/launch/example.launch @@ -1,6 +1,11 @@ - + + + + + + @@ -12,7 +17,7 @@ - + @@ -24,11 +29,6 @@ - - - - - diff --git a/src/client/client_node.py b/src/client/client_node.py index aa8d7e1..e53f68e 100755 --- a/src/client/client_node.py +++ b/src/client/client_node.py @@ -3,7 +3,6 @@ import rospy import time import publishermanager as pm -import json from rospy_message_converter import message_converter as mc from connection import Connection @@ -48,8 +47,7 @@ def callback(msg): data["type"] = msg_type data["stamp"] = time.time() data["msg"] = mc.convert_ros_message_to_dictionary(msg) - payload = json.dumps(data) - self.conn.send_message(payload) + self.conn.send_message(data) return callback diff --git a/src/client/connection.py b/src/client/connection.py index 91f89ed..3152658 100644 --- a/src/client/connection.py +++ b/src/client/connection.py @@ -1,7 +1,6 @@ +# import zlib import threading -import string -import sys import json import copy from twisted.internet import reactor @@ -20,7 +19,7 @@ def onConnect(self, reponse): def onMessage(self, payload, is_binary): if not is_binary: data = json.loads(payload) - MMClient.updates[data["topic"]] = payload + MMClient.updates[data["topic"]] = data @staticmethod def send_message(payload): @@ -46,7 +45,8 @@ def run(self): def stop(self): reactor.stop() - def send_message(self, payload): + def send_message(self, data): + payload = json.dumps(data) return MMClient.send_message(payload) def updates(self): diff --git a/src/client/publishermanager.py b/src/client/publishermanager.py index eb4bce8..b8beeb8 100644 --- a/src/client/publishermanager.py +++ b/src/client/publishermanager.py @@ -1,5 +1,5 @@ + import rospy -import json from rospy_message_converter import message_converter @@ -16,8 +16,7 @@ def create_msg(self, msg_dict, msg_type): msg_type, msg_dict) return msg, msg_cls - def publish(self, payload): - data = json.loads(payload) + def publish(self, data): msg, msg_cls = self.create_msg(data["msg"], data["type"]) topic = data["topic"] if not topic in self.pubs.keys(): diff --git a/src/server/server_node.py b/src/server/server_node.py index 25ce7d5..52f398d 100755 --- a/src/server/server_node.py +++ b/src/server/server_node.py @@ -23,6 +23,6 @@ def run_server(host, port): if __name__ == "__main__": rospy.init_node(NODE_NAME, anonymous=False) - host = rospy.get_param("~host") - port = rospy.get_param("~port") + host = rospy.get_param("~host", "localhost") + port = rospy.get_param("~port", 9000) run_server(host, port) diff --git a/src/server/ws.py b/src/server/ws.py index 34a6296..add59b8 100644 --- a/src/server/ws.py +++ b/src/server/ws.py @@ -1,4 +1,5 @@ +# import zlib import json import common from autobahn.twisted.websocket import WebSocketServerProtocol