Bind and start socket in start method, not initialiser.

This commit is contained in:
michaelpivato
2020-02-12 12:03:24 +10:30
parent a7d5e8010f
commit 8356ebd35c

View File

@@ -18,7 +18,7 @@ class SlamStreamer:
self._map_meters = map_meters self._map_meters = map_meters
self._lidar_connection = lidar_connection self._lidar_connection = lidar_connection
self._port = port self._port = port
self._socket = self._start_socket(self._create_tcp_pub_socket(), port) self._zmq_context = self._create_context()
def start(self): def start(self):
''' '''
@@ -31,6 +31,8 @@ class SlamStreamer:
to calling this method, and changing those values after to calling this method, and changing those values after
calling this method will have no effect. calling this method will have no effect.
''' '''
self._socket = self._start_socket(self._create_socket(self._zmq_context), self._port)
# Block until user opens zmq. # Block until user opens zmq.
self._socket.recv() self._socket.recv()
@@ -80,8 +82,8 @@ class SlamStreamer:
def _create_context(self): def _create_context(self):
return zmq.Context.instance() return zmq.Context.instance()
def _create_tcp_pub_socket(self): def _create_socket(self, context):
return self._create_context().socket(zmq.PAIR) return context.socket(zmq.PAIR)
def _start_socket(self, socket, port): def _start_socket(self, socket, port):
socket.bind('tcp://*:' + str(self._port)) socket.bind('tcp://*:' + str(self._port))