refactor: rename EndpointBase to SocketBase
Because 'endpoint' is also used in the messages, the name 'socket' is more descriptive. ref: N25B-168
This commit is contained in:
38
src/robot_interface/endpoints/socket_base.py
Normal file
38
src/robot_interface/endpoints/socket_base.py
Normal file
@@ -0,0 +1,38 @@
|
||||
from abc import ABCMeta
|
||||
|
||||
|
||||
class SocketBase(object):
|
||||
__metaclass__ = ABCMeta
|
||||
|
||||
name = None
|
||||
socket = None
|
||||
|
||||
def __init__(self, name):
|
||||
"""
|
||||
:param name: The name of the endpoint.
|
||||
:type name: str
|
||||
"""
|
||||
self.name = name
|
||||
self.socket = None
|
||||
|
||||
def create_socket(self, zmq_context, socket_type, port):
|
||||
"""
|
||||
Create a ZeroMQ socket.
|
||||
|
||||
:param zmq_context: The ZeroMQ context to use.
|
||||
:type zmq_context: zmq.Context
|
||||
|
||||
:param socket_type: The type of socket to create. Use zmq constants, e.g. zmq.SUB or zmq.REP.
|
||||
:type socket_type: int
|
||||
|
||||
:param port: The port to use.
|
||||
:type port: int
|
||||
"""
|
||||
self.socket = zmq_context.socket(socket_type)
|
||||
self.socket.connect("tcp://localhost:{}".format(port))
|
||||
|
||||
def close(self):
|
||||
"""Close the ZeroMQ socket."""
|
||||
if not self.socket: return
|
||||
self.socket.close()
|
||||
self.socket = None
|
||||
Reference in New Issue
Block a user