dpallot / simple-websocket-server

A python based websocket server that is simple and easy to use.
951 stars 321 forks source link

Very high latency #86

Closed suraj-pai closed 5 years ago

suraj-pai commented 6 years ago

When using the handle message method and sending a basic unicode string, I am seeing a RTT of ~1100ms on my client. With nothing changed on the client side and using tornado this is now 9ms.

What are the possible causes for this?

dpallot commented 5 years ago

Going to need more info.

himijendrix24 commented 5 years ago

Same problem. I'm using a python script as a websocket server using the Chat server example. The websocket client is javascript running in chromium-browser on a raspberry pi 3. The Raspberry has a fixed IP 192.168.0.10 and ping timings are <0.15ms. Wifi is disabled. There is no difference if the raspberry is connected to a router or not ... I have no idea what could cause the problem.

Websocket client code:

<script>
      var WS_URL = "ws://192.168.0.10:80";
      function connect() {
        console.log("attempting connection");

        var ws = new WebSocket(WS_URL);
        ws.onopen = function() {
          console.log("connection open");
          ws.send("hello");
        };

        ws.onmessage = function(event) {
          console.log("received:");
          console.log(event.data);
              };

        ws.onclose = function(e) {
          console.log(
            "Socket is closed. Reconnect will be attempted in 1 second.",
            e.reason
          );
          setTimeout(function() {
            connect();
          }, 500);
        };

        ws.onerror = function(err) {
          console.error(
            "Socket encountered error: ",
            err.message,
            "Closing socket"
          );
          ws.close();
        };
      }

      // start websocket
      connect();
    </script>