Socket Operations¶
socket_operations.py¶
Functions for creating and using sockets for inter-process communication (IPC). The code below shows a minimal example.
In one process:
import socket_operations as so
from options import Options
options = Options()
sock = so.create_sockets(
options.router_address,
"BOREALIS_USER"
)
so.send_string(sock, "OTHER_BOREALIS_USER", "Good choice")
In another process:
import socket_operations as so
from options import Options
options = Options()
sock = so.create_sockets(
options.router_address,
"OTHER_BOREALIS_USER"
)
msg = so.recv_string(sock, "BOREALIS_USER")
assert msg == "Good choice"
- todo:
log.debug all functions
- src.utils.socket_operations.create_sockets(router_addr, *identities)[source]¶
Creates a
DEALERsocket for each identity in the list argument. Each socket is then connected to the router.
- src.utils.socket_operations.recv_bytes(socket, sender_identity, log=None, with_header=False)[source]¶
Receives data from a socket and verifies it comes from the correct sender.
- src.utils.socket_operations.recv_bytes_from_any_iden(socket, with_header=False)[source]¶
Receives data from a socket, returns just the data and strips off the identity
- src.utils.socket_operations.recv_pyobj(
- socket,
- sender_identity,
- log=None,
- expected_type=None,
- with_header=False,
Receive a pickled Python object.
Can be used to check if the received object is of
expected_type.- Parameters:
- Returns:
an object
- Return type:
Any
- src.utils.socket_operations.recv_string(socket, sender_identity, log=None, with_header=False)[source]¶
Receives data from a socket and verifies it comes from the correct sender.
- src.utils.socket_operations.send_bytes(
- socket,
- receiver_identity,
- bytes_object,
- log=None,
- header=None,
Sends experiment to another identity.
- src.utils.socket_operations.send_pyobj(
- socket,
- receiver_identity,
- message,
- log=None,
- header=None,
Pickles the message and passes it to send bytes to be communicated over the router.