I have a really simple websocket test on chrome, but it seems to be failing miserably:
var ws = new WebSocket('ws://localhost:8002/', 'a')
ws.onopen(function() {
console.log("ok")
})
It tells me: Uncaught TypeError: Property 'onopen' of object #<WebSocket> is not a function
. I would assume that onopen should exist as a method whether or not there is a websocket server actually running, but I do have one running on that port.
I'm using chrome 32.0.1700. I see that all of the callback methods (onopen, onmessage, etc) are all null. What's going on here?
The function is not correctly assigned to the onopen event. Do it like this instead:
var ws = new WebSocket('ws://localhost:8002/', 'a')
ws.onopen = function() {
console.log("ok")
};
http://www.tutorialspoint.com/html5/html5_websocket.htm
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With