Skip to content

Instantly share code, notes, and snippets.

@George3d6
Last active September 16, 2018 23:15
Show Gist options
  • Save George3d6/5e370007070b0675e4c4cc3fb4d17484 to your computer and use it in GitHub Desktop.
Save George3d6/5e370007070b0675e4c4cc3fb4d17484 to your computer and use it in GitHub Desktop.
extern crate tokio;
extern crate futures;
use futures::future;
use tokio::{net::TcpStream, prelude::Future};
use std::net::SocketAddr;
fn send(addr: SocketAddr, message: String) {
let task = TcpStream::connect(&addr)
.and_then(|stream| tokio::io::write_all(stream, message))
.map_err(|e| println!("Error: {}", e))
.map(|_| ());
tokio::spawn(task);
}
fn main() {
tokio::run(future::lazy(|| {
send("8.8.8.8:1234".parse().unwrap(), String::from("46"));
send("1.1.1.1:4321".parse().unwrap(), String::from("3"));
Ok(())
}));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment