javascriptwebsocketudpdartonline-game

Why can not I open a UDP connection on the client side (in browser)?


I know that there WebSockets. I looked at it from itself is an example of language dart.

void initWebSocket([int retrySeconds = 2]) {
  var reconnectScheduled = false;

  outputMsg("Connecting to websocket");
  ws = new WebSocket('ws://echo.websocket.org');

  void scheduleReconnect() {
    if (!reconnectScheduled) {
      new Timer(new Duration(milliseconds: 1000 * retrySeconds), () => initWebSocket(retrySeconds * 2));
    }
    reconnectScheduled = true;
  }

  ws.onOpen.listen((e) {
    outputMsg('Connected');
    ws.send('Hello from Dart!');
  });...

That is nothing but the creation of new connections and work with it already. That is a separate thread (in fact, in which runs javaScript) connection is established and so on. Why then dart and JavaScript I can not in the same thread to open a simple UDP connection and work with him?

P.s.UDP is more preferred for online-browser-realtime-games.


Solution

  • The browsers don't support it due to security constraints.
    You should take a look at WebRTC

    see also