I am new to rust and very new to bevy, and I'm trying to make a game that will require a lot of IPC. I also just figured out how to do IPC just recently, producing a basic proof of concept using zero mq. So I tried to make a component to store the socket data, so I can then call a system on said component to receive messages over IPC. The problem is bevy doesn't seem to like that for synchronization reasons that I don't fully understand yet. Also i understand that this is partially due to the interaction between zmq and bevy; if you can tell me a better way to do IPC in bevy then please do.
#[derive(Component)]
struct ReceiverComponent {
context:zmq::Context,
socket:zmq::Socket,
addr:String,
}
fn init_listener(mut commands:Commands) {
let context = zmq::Context::new();
let socket = match context.socket(zmq::REP) {
Ok(socket) => socket,
Err(..) => panic!("couldn't open socket"),
};
let addr = "ipc:///tmp/daemoncraft.ipc";
socket.bind(addr);
commands.spawn(
ReceiverComponent {
context:context,
socket:socket,
addr:addr.to_string(),
}
);
}