diff --git a/scripts/run_server.py b/scripts/run_server.py index e69de29..e2b1756 100644 --- a/scripts/run_server.py +++ b/scripts/run_server.py @@ -0,0 +1,22 @@ + +import os +import sys + +sys.path.append(os.path.join(os.path.dirname(__file__), "../src")) + +import server +from twisted.python import log +from twisted.internet import reactor +from autobahn.twisted.websocket import WebSocketServerFactory + + +def run_server(): + log.startLogging(sys.stdout) + factory = WebSocketServerFactory("ws://localhost:9000", debug=True) + factory.protocol = server.MMServerProtocol + reactor.listenTCP(9000, factory) + reactor.run() + + +if __name__ == "__main__": + run_server() diff --git a/src/client/connection.py b/src/client/connection.py index 1f1f8fe..91f89ed 100644 --- a/src/client/connection.py +++ b/src/client/connection.py @@ -50,6 +50,6 @@ def send_message(self, payload): return MMClient.send_message(payload) def updates(self): - payloads = copy.deepcopy(MMClient.updates) + payloads = copy.copy(MMClient.updates) MMClient.updates = dict() return payloads diff --git a/src/client/node.py b/src/client/node.py index e07407d..de36aff 100644 --- a/src/client/node.py +++ b/src/client/node.py @@ -27,12 +27,10 @@ def __init__(self, host, port, name, topics): def run(self): for topic, msg_type in self.topics: self.create_subscriber(topic, msg_type) - r = rospy.Rate(30) while not rospy.is_shutdown(): updates = self.conn.updates() for v in updates.values(): self.pub_man.publish(v) - r.sleep() def create_subscriber(self, topic, msg_type): namespace, msg_name = msg_type.split("/") diff --git a/tests/ws_test.py b/tests/ws_test.py deleted file mode 100644 index 92646d7..0000000 --- a/tests/ws_test.py +++ /dev/null @@ -1,71 +0,0 @@ - -import os -import sys - -sys.path.append(os.path.join(os.path.dirname(__file__), "../src")) - -import server -import time -from twisted.internet import task -from twisted.python import log -from twisted.internet import reactor -from autobahn.twisted.websocket import WebSocketServerFactory -from autobahn.twisted.websocket import WebSocketClientProtocol -from autobahn.twisted.websocket import WebSocketClientFactory - - -test_msg = """ -{"to": "bar", - "from": "foo", - "topic": "/foo/state", - "type": "geometry_msgs/Point", - "msg": "{'x': 0, 'y': 0, 'z': 0}", - "stamp": 0} -""" - - -class ClientProtocol(WebSocketClientProtocol): - - def onConnect(self, response): - print("Server connected: {0}".format(response.peer)) - - def onOpen(self): - print("WebSocket connection open.") - - def hello(): - self.sendMessage(test_msg) - self.factory.reactor.callLater(1, hello) - - hello() - - def onMessage(self, payload, is_binary): - if not is_binary: - print payload - - def onClose(self, wasClean, code, reason): - print("WebSocket connection closed: {0}".format(reason)) - - -def print_conns(): - print server.clients - - -def create_websocket(): - factory = WebSocketClientFactory(u"ws://127.0.0.1:9000/foo", debug=True) - factory.protocol = ClientProtocol - reactor.connectTCP("127.0.0.1", 9000, factory) - - factory = WebSocketClientFactory(u"ws://127.0.0.1:9000/bar", debug=True) - factory.protocol = ClientProtocol - reactor.connectTCP("127.0.0.1", 9000, factory) - - - -def test_ws_server(): - log.startLogging(sys.stdout) - # create_websocket() - factory = WebSocketServerFactory("ws://localhost:9000", debug=True) - factory.protocol = server.MMServerProtocol - reactor.listenTCP(9000, factory) - # task.LoopingCall(print_conns).start(1.0) - reactor.run()