Hi,
I try to use tokio-core 0.1 library to send and receive some message over tcp socket, but I have problem with understanding futures and get program compiled.
Here is my code:
fn new_connection(socket: TcpStream, client_address: std::net::SocketAddr) {
let b = generate_public();
let (to_client, from_client) = socket.framed(ServerPublicNumberCodec::new()).split();
let send_server_number = to_client
.send(ServerPublicNumber::new(b));
let read_client_number = from_client
.into_future()
.and_then(move |number_msg| {
Ok(number_msg)
});
let joined = send_server_number.join(read_client_number);
joined.poll();
}
I try to get at the end future which I could poll. I would like this to work with sending and receiving in any order.
while compiling I get an error:
error[E0271]: type mismatch resolving `<futures::AndThen<futures::stream::StreamFuture<futures::stream::SplitStream<tokio_core::io::Framed<tokio_core::net::TcpStream, common::codec::LengthPrefixedJson<common::ClientPublicNumber, common::ServerPublicNumber>>>>, std::result::Result<(std::option::Option<common::ClientPublicNumber>, futures::stream::SplitStream<tokio_core::io::Framed<tokio_core::net::TcpStream, common::codec::LengthPrefixedJson<common::ClientPublicNumber, common::ServerPublicNumber>>>), (std::io::Error, futures::stream::SplitStream<tokio_core::io::Framed<tokio_core::net::TcpStream, common::codec::LengthPrefixedJson<common::ClientPublicNumber, common::ServerPublicNumber>>>)>, [closure@src/main.rs:83:23: 85:14]> as futures::IntoFuture>::Error == std::io::Error`
--> src/main.rs:87:41
|
87 | let joined = send_server_number.join(read_client_number);
| ^^^^ expected tuple, found struct `std::io::Error`
|
= note: expected type `(std::io::Error, futures::stream::SplitStream<tokio_core::io::Framed<tokio_core::net::TcpStream, common::codec::LengthPrefixedJson<common::ClientPublicNumber, common::ServerPublicNumber>>>)`
found type `std::io::Error`
error[E0271]: type mismatch resolving `<futures::AndThen<futures::stream::StreamFuture<futures::stream::SplitStream<tokio_core::io::Framed<tokio_core::net::TcpStream, common::codec::LengthPrefixedJson<common::ClientPublicNumber, common::ServerPublicNumber>>>>, std::result::Result<(std::option::Option<common::ClientPublicNumber>, futures::stream::SplitStream<tokio_core::io::Framed<tokio_core::net::TcpStream, common::codec::LengthPrefixedJson<common::ClientPublicNumber, common::ServerPublicNumber>>>), (std::io::Error, futures::stream::SplitStream<tokio_core::io::Framed<tokio_core::net::TcpStream, common::codec::LengthPrefixedJson<common::ClientPublicNumber, common::ServerPublicNumber>>>)>, [closure@src/main.rs:83:23: 85:14]> as futures::Future>::Error == std::io::Error`
--> src/main.rs:87:41
|
87 | let joined = send_server_number.join(read_client_number);
| ^^^^ expected tuple, found struct `std::io::Error`
|
= note: expected type `(std::io::Error, futures::stream::SplitStream<tokio_core::io::Framed<tokio_core::net::TcpStream, common::codec::LengthPrefixedJson<common::ClientPublicNumber, common::ServerPublicNumber>>>)`
found type `std::io::Error`
= note: required by `futures::Join`