Code Monkey home page Code Monkey logo

Comments (5)

cTatu avatar cTatu commented on August 17, 2024

And I have not seen anything related to how to send it from the client side either.

from web_socket_channel.

mhstoller avatar mhstoller commented on August 17, 2024

And I have not seen anything related to how to send it from the client side either.

You send it using the IOWebSocketChannel's pingInterval property:

 var channel =
      IOWebSocketChannel.connect('url_goes_here', pingInterval: Duration(seconds: 10));

The client will send a ping every 10 seconds, and wait for a 'pong' back from the server.

Documentation doesn't explain how to respond to ping event on server side.
ws.pong() and ws.send('pong) didn't work.

The library automatically responds to server ping events, no configuration is needed for that. It's part of the RFC 6455 spec.

from web_socket_channel.

brax10ward avatar brax10ward commented on August 17, 2024

Documentation doesn't explain how to respond to ping event on server side.
ws.pong() and ws.send('pong) didn't work.

The library automatically responds to server ping events, no configuration is needed for that. It's part of the RFC 6455 spec.

@mhstoller I am hoping you could shed some more light on the automatic response to server ping events.

We have a node WebSocket server that is using the RFC 6455 spec and sends a ping every 30 seconds to our flutter app.

The flutter app is connecting to the WebSocket server like this example below.

 var channel =
      IOWebSocketChannel.connect('url_goes_here', pingInterval: Duration(seconds: 15));

The server never receives a pong response and subsequently closes the WebSocket connection.

Can you point me to any documentation or where in the library the automatic response happens?

Should the server be expecting something besides pong in response?

from web_socket_channel.

mhstoller avatar mhstoller commented on August 17, 2024

@brax10ward so coming back to this a year later I don't want to dig through the code, but I did a cursory look and there's code like this:

case _WebSocketOpcode.PING:
            _eventSink!.add(_WebSocketPing());
            break;
          case _WebSocketOpcode.PONG:
            _eventSink!.add(_WebSocketPong());
            break;

I would guess that it responds to ping events with a ping of its own. With it being part of the spec though I would assume it's something that can be handled in the node library you are using without much work on your end.

That said, I was trying to set something similar up for my own connections and you can read what I ended up doing in the comments here: #124

from web_socket_channel.

lukepighetti avatar lukepighetti commented on August 17, 2024

I think that is transforming a Ping opcode on the wire into a Ping event in the application code.

The section we are looking for is
web_socket_impl.dart:L724

from web_socket_channel.

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.