tcp_stream.rs 541 B

1234567891011121314
  1. use std::io::Write;
  2. use wasmedge_wasi_socket::{Shutdown, TcpStream};
  3. fn main() -> std::io::Result<()> {
  4. let port = std::env::var("PORT").unwrap_or("1234".to_string());
  5. println!("connect to 127.0.0.1:{}", port);
  6. let mut stream = TcpStream::connect(format!("127.0.0.1:{}", port))?;
  7. println!("local address {}", stream.local_addr().unwrap());
  8. println!("peer address {}", stream.peer_addr().unwrap());
  9. println!("sending hello message...");
  10. stream.write(b"hello")?;
  11. stream.shutdown(Shutdown::Both)?;
  12. Ok(())
  13. }