Comments (5)
I guess it's neither tokio-tungstenite
, nor tokio-timer
, it's just that sometimes it's really a challenge to figure out where the Rust error comes from. I personally also think that it's quite annoying when such errors occur without a [visible] reason, if you want you can create an issue in tokio-timer
repository and referenec this issue, maybe we'll get some insights which explain why exactly this code stopped compiling after adding tokio-timer
. But it seems more like a general problem with the way Rust shows errors, sometimes it's extremely unobvious and the one has to spend a lot of time to figure out what's going on there.
Nevertheless, I found a solution for you which fixes this issue and makes the code compilable again. Here is the diff:
diff --git a/examples/server.rs b/examples/server.rs
index c757829..998c646 100644
--- a/examples/server.rs
+++ b/examples/server.rs
@@ -21,6 +21,7 @@ extern crate futures;
extern crate tokio_core;
extern crate tokio_tungstenite;
extern crate tungstenite;
+extern crate tokio_timer;
use std::cell::RefCell;
use std::collections::HashMap;
@@ -28,13 +29,14 @@ use std::env;
use std::io::{Error, ErrorKind};
use std::rc::Rc;
-use futures::stream::Stream;
-use futures::Future;
-use tokio_core::net::TcpListener;
+use futures::stream::{Stream, SplitSink};
+use futures::{Future, Sink};
+use futures::sync::mpsc::UnboundedSender;
+use tokio_core::net::{TcpListener, TcpStream};
use tokio_core::reactor::Core;
use tungstenite::protocol::Message;
-use tokio_tungstenite::accept_async;
+use tokio_tungstenite::{accept_async, WebSocketStream};
fn main() {
let addr = env::args().nth(1).unwrap_or("127.0.0.1:8080".to_string());
@@ -86,15 +88,14 @@ fn main() {
.filter(|&(&k, _)| k != addr)
.map(|(_, v)| v);
for tx in iter {
- tx.send(message.clone()).unwrap();
+ (tx as &UnboundedSender<Message>).send(message.clone()).unwrap();
}
Ok(())
});
// Whenever we receive a string on the Receiver, we write it to
// `WriteHalf<WebSocketStream>`.
- let ws_writer = rx.fold(sink, |mut sink, msg| {
- use futures::Sink;
+ let ws_writer = rx.fold(sink, |mut sink, msg| -> Result<SplitSink<WebSocketStream<TcpStream>>, ()> {
sink.start_send(msg).unwrap();
Ok(sink)
});
from tokio-tungstenite.
@bbigras have you tried the workaround? (the server.rs code compiles well with it)
Did it help you to compile the code? (if so, feel free to close the issue)
from tokio-tungstenite.
@bbigras this has to do with UnboundedSender
and Sink
both exposing send
fns. Here's the related issue: rust-lang/futures-rs#261.
from tokio-tungstenite.
@compressed this particular issue was caused by a fold()
argument, after adding tokio-timer
as external crate, Rust cannot make a type inference for the passed closure (don't know why).
I've also noticed the problem with UnboundedSender
and Sink
in the past and previously the example workarounded that by importing futures::Sink
only when the Sink
trait is actually used. But in my latest diff I decided to rewrite that part with UnboundedSender::send()
explicitly. But I did not know that it's already being worked on and was discussed in futures-rs
, so good to know :)
from tokio-tungstenite.
Did it help you to compile the code? (if so, feel free to close the issue)
Yes. Thanks.
from tokio-tungstenite.
Related Issues (20)
- Passing body in `connect`? HOT 2
- Can we provided a way to keep the original header name case. HOT 1
- 403 Forbidden HOT 1
- "WebSocket protocol error: httparse error: invalid token" when connect from ngrok tcp tunnel. HOT 5
- Is it possible to bind client to specific interface? HOT 1
- 没有连接断开时,直接检测客户端的状态的api,以实现重新连接,这在其它语言中都是常见的
- Performance boost implementing `poll_write_vectored` and rustls 0.23 HOT 2
- Is MaybeTlsStream supposed to work for servers too? HOT 2
- 0.20 and 0.21 break something HOT 25
- Vectorized send HOT 2
- new rustls 0.23.x is incompatible with the 0.22.x used by tokio-tungstenite HOT 2
- Adding authorization header leads in infinite block of connect_async HOT 2
- How to correctly handle large messages HOT 1
- How can I send pong frames as heartbeats from a client? HOT 4
- Specify default-features = false for rustls in Cargo.toml
- Websocket missing some ping messages. HOT 2
- tokio-tungstenite not using version 0.22 of tungstenite HOT 1
- no process-level CryptoProvider available -- call CryptoProvider::install_default() before this point HOT 5
- No option to enable `url` flag on `tungstenite` HOT 1
- How to reply to the client and send a message if an error occures on `accept_async` funtion. HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tokio-tungstenite.