Giter Club home page Giter Club logo

Comments (1)

daniel-abramov avatar daniel-abramov commented on August 14, 2024

When a new stream connects I want to send messages directly back and forth between that client

Do you want to write an echo-server?

I noticed in tungstenite-rs the autobahn server example does though. Is it similar to that?

We do have the same autobahn server example for tokio-tungstenite.

I've tried sending using the sink but I can't because ws_writer uses it.

If you're talking about the chat server example that we have in our "examples" directory, then of course you can't use sink directly as it's consumed (folded). You might have noticed that there is an async MPSC channel created right before splitting the ws_stream. The receiving part of that MPSC channel is attached to sink, so you can use the sender part to send messages. There is a map of all connections which holds all users and their corresponding tx parts. The only reason the message is not echoed to the recipient back is this line. If you want, you can simply move your tx handle which corresponds to the client into your for_each future and just send replies to this tx whenever you receive a new message

P.S.: I think that a misunderstanding comes from the fact that the usage of the library implies a certain understanding of tokio framework basics. It might be helpful to take a look at tokio docs.

from tokio-tungstenite.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.