You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

client.rs 647B

1234567891011121314151617181920212223242526
  1. use std::net::TcpStream;
  2. fn main() {
  3. let stream = TcpStream::connect("127.0.0.1:8080");
  4. if stream.is_ok() {
  5. println!("Connected to the server!");
  6. } else {
  7. println!("Couldn't connect to server...");
  8. }
  9. loop {
  10. let mut buffer = String::new();
  11. match std::io::stdin().read_line(&mut buffer) {
  12. Ok(n) => {
  13. if n == 0 {
  14. break;
  15. }
  16. println!("{}", buffer);
  17. }
  18. Err(error) => {
  19. println!("error: {error}");
  20. break;
  21. }
  22. }
  23. }
  24. } // the stream is closed here