kataras / go-websocket

:speaker: Deprecated. Use https://github.com/kataras/neffos instead
MIT License
60 stars 16 forks source link

c.Emit has strange behaviour on fast, low latency connections, like localhost or in LAN #10

Closed Ekranos closed 7 years ago

Ekranos commented 7 years ago

When you have a fast, low latency connection, like you have on localhost, you get a lot of weird output.

There is also the interesting thing that the channels get mixed up. In the output below, the message for channel status with the text Idle shouldn't be there.

Output can be like:

Response body size: 2042 bytesgo-websocket-message:log;0;Time to download response body: 1.009msgo-websocket-message:log;0;Total roundtrip time: 176.343msgo-websocket-message:status;0;Idle

Server code:

c.Emit("log", fmt.Sprintf("Response body size: %d bytes", num))
c.Emit("log", fmt.Sprintf("Time to download response body: %s", time.Now().Sub(firstByteTime)))
c.Emit("log", fmt.Sprintf("Total roundtrip time: %s", time.Now().Sub(now)))
c.Emit("status", "Idle")

Client code:

(function ($) {
    var ws = new Ws("ws://localhost:8080/http/tracer/ws");
    var log = $("#log");
    var status = $("#status");

    ws.On("status", function (message) {
        status.text(message);
    });

    ws.On("log", function (message) {
        log.html(log.html() + "<br/>" + message);
    });

    $("#form").submit(function (e) {
        e.preventDefault();

        log.empty();
        ws.Emit("trace", $("#address").val());

        return false;
    })
})(jQuery);
ghost commented 7 years ago

That's strange because my tests were on localhost at the first place and after on dedicated server, please post the full source code ( and backend .go) in order to test it myself and fix it, if it's real an issue with the package, thank you, I'll wait

Ekranos commented 7 years ago

First the download link for the project: https://up.ekranos.me/v/2mDoxt2lYX/QH00G8D6UA2j7RN0

I assumed that it doesn't work on fast, low latency connections, cause adding delays between the emits solved the problem. But I don't want to delay between them.

Interesting files for you are:

ghost commented 7 years ago

It works on my machine on fast, low latency connections, no need to add delays, I'll see your project's code and response back then