A little Rust port IO Hello World program?

People,

I am interested in a “Hello World” level program that can do some text IO through a port - is there anything like this already around? - it would be a convenient thing for me to get started with that I could add to for an actual simple use case . .

Thanks.

What do you mean? Port on a raspberry pi or a microcontroller? I2C?

No, just on a i86_64 PC - so I could talk to the port from another PC . .

Like networking, IP/TCP?

You would need a Server in one side: TcpListener in std::net - Rust

And then connect from the other side: TcpStream in std::net - Rust

After that you can use the TcpStream on both sides to read and write data.

4 Likes

OK, that sounds like what I want . . I will go looking for little programs with those fns in them . .

Thanks!

1 Like

i made a simple server/client program: Mano Vardas / tcp-hello-world · GitLab

the server handles a client at a time. the client just reads all data from the server until the server disconnects, then prints it to the command line. If you want to handle multiple clients at a time you would need to spawn a thread for each one, that is because when reading from a TcpStream the current thread gets “locked up” (blocked) and you can’t do anything else on it (like processing messages from other clients).

you start the server with cargo run --bin tcp-hello-world-server and the client with cargo run --bin tcp-hello-world-client

5 Likes

I guess this example using JSON-RPC over QUIC could be useful too: https://github.com/maidsafe/sn_api/blob/master/qjsonrpc/examples/ping.rs

1 Like

Thanks @urrtag and @bochaco !

2 Likes

if you have any more questions about eg concepts just ask here.