Code Monkey home page Code Monkey logo

Comments (3)

Totodore avatar Totodore commented on June 17, 2024 2

Because the protocol specification doesn't specify that the initial connect response should be alone. And with http polling it is possible to have multiple packets in one response:

So for performance reasons if two packets are emitted at almost the same time they will be buffered.

while let Some(item) = internal_rx.recv().await {
map_fn!(item);
// For every available packet we continue to send until the channel is drained
while let Ok(item) = internal_rx.try_recv() {
map_fn!(item);
}
tx.flush().await.ok();

If you have any other questions, please open a discussion in the discussions panel or on the #socketioxide channel on the tokio discord server

from socketioxide.

Totodore avatar Totodore commented on June 17, 2024 1

Could you please add a demo code of the client and server? Without this I won't be able to see what's wrong.
I suspect that it is the client that is not configured correctly to upgrade to websocket. As it is the responsability of the client to initialize a websocket upgrade request.

from socketioxide.

Henrriky avatar Henrriky commented on June 17, 2024

I managed to fix it, in fact, transports was missing: ["polling", "websocket"]. I had only defined polling.

Taking advantage, I would like to know why the emit that I am triggering when the user connects is going along with the Socketioxide connection process?

Here below is an example:

image

Now notice the second image, which indicates where the emitted data is being received:

image

Part of the code that accomplishes this:
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    tracing::subscriber::set_global_default(FmtSubscriber::default())?;

    let messages = state::MessageStore::default();
    let sockets = state::SocketDataStore::default();

    let (layer, io) = SocketIo::builder().with_state(messages).with_state(sockets).build_layer();
    
    io.ns("/", |socket: SocketRef, Data(auth): Data<types::AuthData>, store: State<state::SocketDataStore>| async move {

               fn emit_wrapper(event: String, socket: &SocketRef, id: String, data: impl serde::Serialize) {
                    let _result = socket
                    .within(id)
                    .emit(event, data).ok();
                }

                emit_wrapper("person:connected".to_string(), &socket, socket_data.clone().id.clone().to_string(),
                    types::PersonConnected {
                        user_id: socket_data.clone().user_id,
                        extension: socket_data.clone().extension.clone().unwrap_or("".to_string()),
                    }
                );
    });
        let app = axum::Router::new()
        .route("/", get(|| async { "Hello, World!" }))
        .route("/hello", get(handler))
        .with_state(io)
        .layer(
            ServiceBuilder::new()
                .layer(CorsLayer::permissive())
                .layer(layer),
        );

    info!("Starting server");

    axum::Server::bind(&"0.0.0.0:3010".parse().unwrap())
        .serve(app.into_make_service())
        .await?;

    Ok(())
}

from socketioxide.

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.