#send data between two different rust programs?

16 messages · Page 1 of 1 (latest)

woeful rover
#

how do you send data between two different rust programs on the same computer(not over internet). E.G:

how would you send a String from one rust program to another?

//! sender.rs
pub fn main() {
     let message = "Hello reciever!";
     ... send message
}

//! reciever.rs
pub fn main() {
   ... recieve message
   println!("message recieved: {:#?}", message)
}
sand sleet
#

This concept is called inter-process communication and there's tons of ways to do it. The simplest way is to connect the stdin of one to the stdout of the other (for example, by piping in a shell) and using the usual println! and stdin() operations to communicate. Beyond that, there's different kinds of sockets and pipes depending on the OS, and network protocols of course work locally as well.

blazing egret
#

and then use whatever serialization format you want with serde to make the binary packets

#

https://docs.rs/interprocess/latest/interprocess/ and https://docs.rs/ipc-channel/latest/ipc_channel/ provide local IPC but they are more annoying to work with than the local network stack

woeful rover
woeful rover
lethal gazelle
#

you know it's not the "internet"?

#

localhost is local only

woeful rover
lethal gazelle
#

no

#

you can use these methods without any internet connection outside

woeful rover
# lethal gazelle you can use these methods without any internet connection outside

https://superuser.com/questions/1137897/does-a-localhost-request-connect-to-the-network

I didn't realize localhost doesn't connect to the internet. I remember doing ssh stuff through localhost though?

lethal gazelle
#

then it must have been on the same computer too

#

you can connect locally with ssh