Utils#
Socket utility functions for ZeroMQ and general networking operations.
- brainmaze_zmq.utils.check_port(ip_address: str, port: int)#
Checks if a port on a given IP address is open.
- Parameters:
ip_address (str) – IP address to check.
port (int) – Port number to check.
- Returns:
True if the port is open, False otherwise.
- Return type:
bool
- brainmaze_zmq.utils.is_socket_alive(socket_instance: Socket)#
Checks if a ZeroMQ socket is alive and operational.
- Parameters:
zmq_socket (zmq.Socket) – ZeroMQ socket to check.
- Returns:
True if the socket is alive, False otherwise.
- Return type:
bool
- brainmaze_zmq.utils.ping_ip(ip_address: str)#
Pings an IP address to check connectivity.
- Parameters:
ip_address (str) – IP address to ping.
- Returns:
True if the ping is successful, False otherwise.
- Return type:
bool
- brainmaze_zmq.utils.send_exit_signal(port, context=None)#
Sends an exit signal to a specific ZeroMQ port.
- Parameters:
port (int) – Port to send the exit signal.
context (zmq.Context, optional) – ZeroMQ context to use. If not provided, a new one is created.
- Returns:
Always returns False (placeholder for success indication).
- Return type:
bool
- brainmaze_zmq.utils.setup_publisher_socket(port, context)#
Sets up a ZeroMQ PUB socket.
- Parameters:
port (int) – Port to bind the socket to.
context (zmq.Context) – ZeroMQ context to use.
- Returns:
Configured PUB socket.
- Return type:
zmq.Socket
- brainmaze_zmq.utils.setup_pull_socket(port, context)#
Sets up a ZeroMQ PULL socket.
- Parameters:
port (int) – Port to bind the socket to.
context (zmq.Context) – ZeroMQ context to use.
- Returns:
Configured PULL socket.
- Return type:
zmq.Socket
- brainmaze_zmq.utils.setup_push_socket(port, context)#
Sets up a ZeroMQ PUSH socket.
- Parameters:
port (int) – Port to connect the socket to.
context (zmq.Context) – ZeroMQ context to use.
- Returns:
Configured PUSH socket.
- Return type:
zmq.Socket
- brainmaze_zmq.utils.setup_reply_socket(port, context)#
Sets up a ZeroMQ REP socket.
- Parameters:
port (int) – Port to bind the socket to.
context (zmq.Context) – ZeroMQ context to use.
- Returns:
Configured REP socket.
- Return type:
zmq.Socket
- brainmaze_zmq.utils.setup_request_socket(port, context)#
Sets up a ZeroMQ REQ socket.
- Parameters:
port (int) – Port to connect the socket to.
context (zmq.Context) – ZeroMQ context to use.
- Returns:
Configured REQ socket.
- Return type:
zmq.Socket
- brainmaze_zmq.utils.setup_subscriber_socket(port, sub_topic, context)#
Sets up a ZeroMQ SUB socket.
- Parameters:
port (int) – Port to connect the socket to.
sub_topic (str) – Subscription topic filter.
context (zmq.Context) – ZeroMQ context to use.
- Returns:
Configured SUB socket.
- Return type:
zmq.Socket