diff options
author | Denis <gilaldpellaeon@gmail.com> | 2018-03-22 18:02:01 +0100 |
---|---|---|
committer | Carl Lerche <me@carllerche.com> | 2018-03-22 10:02:01 -0700 |
commit | 6bdfa159a7082d9b7c441d06ba3c6ebca7bb668a (patch) | |
tree | 51eef5a6d58ec9ad9628533e8684f1d5f22c5c4f /examples | |
parent | 5d87a9cee1e0069f436168a9884b6a325cd7f37d (diff) |
Fix `connect` example for UDP (#241)
Close #241
Diffstat (limited to 'examples')
-rw-r--r-- | examples/connect.rs | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/examples/connect.rs b/examples/connect.rs index f3ea6970..f44a5c1e 100644 --- a/examples/connect.rs +++ b/examples/connect.rs @@ -198,24 +198,29 @@ mod udp { // All bytes from `stdin` will go to the `addr` specified in our // argument list. Like with TCP this is spawned concurrently - tokio::spawn(stdin.map(move |chunk| { + let forward_stdin = stdin.map(move |chunk| { (chunk, addr) }).forward(sink).then(|result| { if let Err(e) = result { panic!("failed to write to socket: {}", e) } Ok(()) - })); + }); // With UDP we could receive data from any source, so filter out // anything coming from a different address - Box::new(stream.filter_map(move |(chunk, src)| { + let receive = stream.filter_map(move |(chunk, src)| { if src == addr { Some(chunk.into()) } else { None } - })) + }); + + Box::new(future::lazy(|| { + tokio::spawn(forward_stdin); + future::ok(receive) + }).flatten_stream()) } } |