Search code examples
dartrikulo

Rikulo websockets and channels


Does rikulo stream v 0.7.2 support web sockets with different channels? I have seen so far only examples with static resource files.


Solution

  • To handle Web Socket, you can use WebSocketTransformer to upgrade HTTP connection to WebSocket connection:

    new StreamServer(uriMapping: {
      "/cmd", (HttpConnect connect) =>
          WebSocketTransformer.upgrade(connect.request)
          .then((websocket) {
            websocket.listen((evt) {
              websocket.add("Server received: $evt");
            });
            return socket.done;
          })
    }).start();
    

    Note: Web Socket is supported directly since Rikulo Stream 0.8.0. Please refer to the WebSocket Handling section.