def _bind_socket(self, socket, addr=None, transport=None):
"""
Bind a socket using the corresponding transport and address.
Parameters
----------
socket : zmq.Socket
Socket to bind.
addr : str, default is None
The address to bind to.
transport : str, AgentAddressTransport, default is None
Transport protocol.
Returns
-------
addr : str
The address where the socket binded to.
"""
if transport == 'tcp':
host, port = address_to_host_port(addr)
if not port:
uri = 'tcp://%s' % self.host
port = socket.bind_to_random_port(uri)
addr = self.host + ':' + str(port)
else:
socket.bind('tcp://%s' % (addr))
else:
if not addr:
addr = str(unique_identifier())
if transport == 'ipc':
addr = config['IPC_DIR'] / addr
socket.bind('%s://%s' % (transport, addr))
return addr
评论列表
文章目录