connor
November 21, 2019, 2:18am
1
Hi everyone,
I am nearing completion of TRPL (Currently on chapter 20). I understood the first section well, and proceeded to recreate the example:
use std::net::TcpListener;
fn main() {
let listener = TcpListener::bind("127.0.0.1:7878").unwrap();
println!("{:?}", listener);
for stream in listener.incoming() {
match stream {
Ok(stream) => {
println!("new client");
}
Err(e) => {
println!("connection failed");
}
}
}
}
I believe I am connecting to the server, because my program continues to run. However, nothing is printed to the terminal!
Output:
Finished dev [unoptimized + debuginfo] target(s) in 1.42s
Running `target/debug/hello`
TcpListener { addr: V4(127.0.0.1:7878), fd: 3 }
I have had trouble finding a solution in the documentation. Does anyone know why new client
is not printing to the terminal?
Thanks,
Connor
How are you connecting to this server?
ZiCog
November 21, 2019, 3:11am
3
Yes, what do you mean by that?
The code you have presented is the server.
You will need to connect to it with a client to see anything happen.
Try running that code and then connecting to it with netcat or telnet.
Or connect to it with a client you write in Rust of course!
1 Like
connor
December 14, 2019, 3:38am
4
Sorry, I did not previously understand that I needed to run the client in my browser.
ZiCog
December 14, 2019, 4:29am
5
But you don't need a browser to run that example client code.
Just run them from the command line. Server in one console window, client in another.
Actually I don't see how you can run that client in a browser.
netcat 127.0.0.1 7878
Or it might be nc
for short.
It might be an interesting project to write a minimal netcat in rust as well as connect to a server like above it can listen on a port. Two netcats can communicate back and forth if one connects to the other that is listening (I think)
system
Closed
March 13, 2020, 10:47am
7
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.