2

im currently building a flask application which uses websockets. For this i would like to use the flask-socketio library. I have copied the client example as per the docs instructions:

<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/socket.io/0.9.16/socket.io.min.js"></script>
<script type="text/javascript" charset="utf-8">
    var socket = io.connect('http://' + document.domain + ':' + location.port);
    socket.on('connect', function() {
        socket.emit('hello', {data: 'Hello there!'});
    });
</script>

and a simple server side handler:

@socketio.on('hello')
def handle_hello(message):
    print message

however i get the following error in the borwserwindow console:

Uncaught TypeError: Cannot read the property 'onClose' of null.

Anybody know what im doing wrong here?

3 Answers 3

1

thats cuz you're fetching the wrong javascipt file for socket.io in your client app. change

<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/socket.io/0.9.16/socket.io.min.js"></script>

to

<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/1.4.6/socket.io.js">
Sign up to request clarification or add additional context in comments.

Comments

0

I have encountered the same problem. The reason is not compatible with python module. You can try to install these versions.

gevent-1.1b1
greenlet-0.4.9
Flask-SocketIO-0.6.0

It's workd for me.

1 Comment

By the way, sockjs-1.1.0 have some problem. You can use sockjs-1.0.3 or sockjs-1.1.1
0

I have the same problem, when i change version from 0.9.16 to 1.3.6 it worked for me.

<script src="//cdnjs.cloudflare.com/ajax/libs/socket.io/1.3.6/socket.io.min.js"></script>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.