Code Monkey home page Code Monkey logo

Comments (15)

Hywan avatar Hywan commented on May 18, 2024

Excuse me, but what did you do exactly?

from websocket.

webspec2012 avatar webspec2012 commented on May 18, 2024

Sample server:

date_default_timezone_set('UTC');
require_once "vendor/autoload.php";
if (!defined('HOA')) {
    die("Failed start daemon: Hoa-socket lib not found");
}

// get unique client ID
function getClientId($bucket) {
    return $bucket->getSource()->getConnection()->getCurrentNode()->getId();
}

// server run
$websocket = new Hoa\Websocket\Server(
    new Hoa\Socket\Server('tcp://0.0.0.0:3333')
);

$websocket->on('open', function ( Hoa\Core\Event\Bucket $bucket ) {

    echo 'new connection #', getClientId($bucket), "\n";

    return;
});

$websocket->on('message', function ( Hoa\Core\Event\Bucket $bucket ) {

    $data = $bucket->getData();
    echo '> message ', $data['message'], "\n";
    $bucket->getSource()->send($data['message']);
    echo '< echo', "\n";

    return;
});

$websocket->on('close', function ( Hoa\Core\Event\Bucket $bucket ) {
    echo 'connection closed #', getClientId($bucket), "\n";

    return;
});

$websocket->run();

Sample Client:
http://fulledu.ru/websocket/

<input type="text" id="input" placeholder="Message…" />
<hr />
<pre id="output"></pre>

<script>
    function mySocketServer() {
        var host   = 'ws://fulledu.ru:3333';
        var socket = null;
        var input  = document.getElementById('input');
        var output = document.getElementById('output');
        var print  = function ( message ) {

            var samp       = document.createElement('samp');
            samp.innerHTML = message + '\n';
            output.appendChild(samp);

            return;
        };

        input.addEventListener('keyup', function ( evt ) {

            if(13 === evt.keyCode) {

                var msg = input.value;

                if(!msg)
                    return;

                try {

                    socket.send(msg);
                    input.value = '';
                    input.focus();
                }
                catch ( e ) {

                    console.log(e);
                }

                return;
            }
        });

        try {

            socket = new WebSocket(host);
            socket.onopen = function ( ) {

                print('connection is opened');
                input.focus();

                return;
            };
            socket.onmessage = function ( msg ) {

                print(msg.data);

                return;
            };
            socket.onclose = function ( ) {
                print('connection is closed');

                setTimeout(function(){mySocketServer()}, 1000 * 2);

                return;
            };
        }
        catch ( e ) {
            console.log(e);
        }
    }

    mySocketServer();
</script>

Result screenshot with Internet Explorer:
http://static.fulledu.ru/example_bug.png

onClose event not work...

from websocket.

Hywan avatar Hywan commented on May 18, 2024

Which version of Internet Explorer are you using?

from websocket.

Hywan avatar Hywan commented on May 18, 2024

I assign @camael24 on this one. He will try to reproduce.

from websocket.

webspec2012 avatar webspec2012 commented on May 18, 2024

"Internet Explorer 11"

The same bug can be reproduced if connection is broken off by the third party.
For example:

  • At the client the Internet was gone
  • Connection with the client was broken off by nginx on timeout (if use nginx proxy for server)

or etc..

from websocket.

Hywan avatar Hywan commented on May 18, 2024

Is it the same issue you reported #31, #32 and #30?

from websocket.

webspec2012 avatar webspec2012 commented on May 18, 2024

Possibly it is other mistakes, for certain I can't tell.

from websocket.

thehawk970 avatar thehawk970 commented on May 18, 2024

I try to reproduce tomorrow :)

from websocket.

thehawk970 avatar thehawk970 commented on May 18, 2024

I confirm the "bug", i reproduce it on IE11

from websocket.

webspec2012 avatar webspec2012 commented on May 18, 2024

It is required that the event of onClose would work anyway if the client was disconnected from the server.

from websocket.

Hywan avatar Hywan commented on May 18, 2024

It's going to be difficult to debug, I don't have Windows. Any idea how could I do that?

from websocket.

thehawk970 avatar thehawk970 commented on May 18, 2024

With an VM ? and an demo key

from websocket.

thehawk970 avatar thehawk970 commented on May 18, 2024

https://www.modern.ie/fr-fr/virtualization-tools

from websocket.

Hywan avatar Hywan commented on May 18, 2024

Perfect! Thanks.

from websocket.

Hywan avatar Hywan commented on May 18, 2024

Here is what need to be considered.

IE sends an unsollicited PONG frame. The RFC6455 says:

A Pong frame MAY be sent unsolicited. This serves as a
unidirectional heartbeat. A response to an unsolicited Pong frame is
not expected.

Several implementations out there (Play, Spring, Go etc.) encountered this issue because receiving an unsollicited PONG was not expected and was creating a bug. In Hoa\Websocket, this is not the case because we handle it as required by the RFC. IE has the fin parameter set to 1, not 0, so this is a valid frame and we don't respond to it.

Since we don't respond, IE sends a random frame that is not a valid one. And yes, random, I don't receive the same frame twice.
After some searches, it seems that this is a known bug in IE10 (not 11). To fix that, we may return a PING. This is what I did, but it does not fix anything. Maybe on IE10, but not on IE11.

Because the bug is still opened on IE10, we can assume this is still present in IE11.

I close this issue because I can't do anything to avoid that… The connection is closed by the server because of the malformed/invalid message we receive after the PONG. IE does not fire the CloseEvent properly despites the server sends a valid close frame!

Sorry for that. If you find a server that handles IE11 properly, I would be glad to know them and look inside the code to see what workaround they found.

from websocket.

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.