Last active
September 16, 2018 23:15
-
-
Save George3d6/5e370007070b0675e4c4cc3fb4d17484 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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