-
• #2
What device are you running this on?
It's possible that it's because you're using
send
right away.new WebSocket
won't be blocking, so it's possible it's not even connected when you're trying to send. -
• #3
Thanks for your reply Gordon!
I'm on esp8266.
I called
ws.initializeConnection();
in the left console, after I sent the code to device. It brought me the following console out:RAW: HTTP/1.1 101 Switching Protocols Upgrade: websocket Connection: Upgrade Sec-WebSocket-Accept: HSmrc0sMlYUkAGmm5OPpG2HaGWk= Handshake Success Connection closed
so, the
ws
is in closed state immediately after initializing, and callingsend()
on a dead socket brings obviously nothing -
• #4
Ahh, thanks. Just looked into this and yes, for some reason (i think it might have been one of my changes for the server), the websocket client got broken.
I just fixed it, so if you upload now it should work.
-
• #5
The connection is established and remains open now, whoohoo!
Although some other problems arose...
If I call e.g.
ws.send( JSON.stringify( { "type":'discoveryResponse', "data":[] } ) );
, then the connection gets closed, and the server logs the following:14:47:53.714 [vert.x-eventloop-thread-0] INFO com.my.GatewayWSVerticle - registered WS for [11.111.111.111] 14:48:26.090 [vert.x-eventloop-thread-0] ERROR i.vertx.core.net.impl.ConnectionBase - io.netty.handler.codec.CorruptedFrameException: unmasked client to server frame 14:48:26.090 [vert.x-eventloop-thread-0] INFO com.my.GatewayWSVerticle - unregistered WS for [11.111.111.111]
If I call
ws.initializeConnection();
then I get to see the following in the logs:14:50:14.331 [vert.x-eventloop-thread-0] ERROR i.vertx.core.net.impl.ConnectionBase - io.netty.handler.codec.CorruptedFrameException: unmasked client to server frame 14:50:14.331 [vert.x-eventloop-thread-0] ERROR i.vertx.core.net.impl.ConnectionBase - io.netty.handler.codec.DecoderException: io.netty.util.IllegalReferenceCountException: refCnt: 0
-
• #6
Hmm... What are you using as your WebSocket server? I was pretty sure masking was optional (so you may find it's a configuration option you can turn off in your server).
-
• #7
I'm using vertx.io. It seems to have masking on by default. here a discussion on masking
btw, would the
ws
module work over thewss
protocol? -
• #8
You might still be able to tweak vertex.io or report it as a bug - after all, the pretty much standard
ws
library seems to work. Although the RFC asks for masking, dropping connections if it's not there is needlessly harsh, especially given the reasons for masking being turned on.I don't have time to fix this right now, but I made an issue for it here: https://github.com/espruino/EspruinoDocs/issues/268
There's some info there if you want to get stuck in and fix it :)
Using the following code in Espruino Web IDE:
I can see in the server logs, that the WS-connection is established and then closes within some milisecs:
If I enter ws.initializeConnection(); in the left-hand side of IDE, I'm getting the lines:
If I connect to the very same server from my browser or from a z-way server @ raspi, then it works like charm.
Am I missing something or is it a WS-bug?
TIA