WebSockets? #686
Replies: 45 comments
-
Posted at 2014-02-27 by @gfwilliams At the moment, it doesn't do WebSockets - but you could still push data with the HTTP client/server. I'm actually in the process of refactoring the HTTP server/network code in the hope that CC3000/WizNet/others can coexist in one binary. Once that's done, implementing WebSockets should be trivial. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-02-27 by mattbrailsford Hey Gordon, That would be awesome! I know it's probably not a priority, but I think it will make an awesome way of communicating with/from the Espruino given that it is becoming a widely used standard. I look forward to seeing how the HTTP refactoring goes, and would be happy to give implementing a WebSocket ago once it is (maybe with a few pointers first :)) Matt |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-03-01 by Sacha Very nice Gordon ! Befor implementing websockets, please implement basic socket connections first ;-). Sacha |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-03-02 by hansamann First let me say the outlook to get websocket support on the espruino is excellent. Also I recently got in touch with SSE - Server Sent Events, which looks like a cool and easy implementation if you just need to send events from the server. http://en.wikipedia.org/wiki/Server-sent_events Essentially the client, e.g. espruino connects to a socket and the server keeps the connection open. A new message is simply seperated via \n and carriage return (or so, details in the spec, but really easy). SSE or WebSockets - I see the espruino being the initiating "client" in these scenarios. It just seems to be the easier option to connect out than trying to expose the local IP/server to the outside. Is this common thinking or is there a better option that I am missing? Also, unfortunately WS/SSE sometimes fail - so an onError handler with the option to recreate the connection could make the connection really stable. Can this be done? I know there is no exception handling, is this required for a onError callback for a websocket? Or is this handled in your integration code and thus no JS Exception handling would be required? |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-03-02 by Sacha Hi Hansamann, SSE is "http" based. Take a look at this implementation of SSE: https://github.com/einaros/sse.js I think SSE could be implemented on top of the existing HTTP implementation we have allready. For WebSockets and other protocols we need basic "net" (socket) support. Sacha |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-03-03 by @gfwilliams There's no reason that there can't be an onError handler added. Overall I think it's quite promising - it's just finding time ;) |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-04-19 by moka +1 for WebSockets! |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-06-04 by Mr.Peu Hi, what's the status on this? |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-06-04 by DrAzzy Socket support is in (see espruino.com/Reference ), but not websockets afaik. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-06-05 by @gfwilliams Yes, there's socket support now so someone could write a WebSocket library in JavaScript pretty easily - I've got way too much other stuff on my plate to work on this at the moment though. The only slightly tricky thing needed is the hash algorithm for setting up a connection, but that shouldn't be hard. Espruino can be natively compiled pretty easily for Linux/Pi/Mac, and WebSocket support could be developed on there, which might make it a little quicker. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-06-05 by Mr.Peu Thanks for your answers. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-10-14 by sameh.hady Guys, I've managed to write a websocket module for Espruino, you can try it out here: Please bare in mind it is still in an early stage, please let me know if you are facing any issues |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-10-14 by LawrenceGrif @sameh.hady thank you for this |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-10-14 by Kolban @sameh.hady You ROCK!! I can't wait to try this out. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-10-14 by sameh.hady Thx guys, looking forward to try it out and give me your feedback |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-10-22 by sameh.hady Thx @d0773d, I had a previous issue before with nodejs crashing and after doing lots of research for error handling etc it didn't actually work as I wanted. Still I found this lovely piece of code that actually prevented nodejs from crashing whatever happens.
Hope it would help. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-10-24 by d0773d @sameh.hady thanks for the help. I will surely give that a try over the weekend and respond back with my results. In the mean time, do you happen to know if I will need to instantiate the node.js ws server again even though the uncaughtException is captured and node.js does NOT crash? |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-10-24 by sameh.hady if the exception is related to the ws server then yes you will need to instantiate the server again, if it is not related then everything should be fine. Question is, why would the ws server crash? this shouldn't happen unless you have an issue in the code. So i recommend you find and fix than just catch |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-10-24 by sameh.hady remember, if the ws server crashed and restarted you will loose all your clients sessions and the clients will act as if they are rejoining again with new session. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-10-27 by d0773d @sameh.hady nodejs ws server has been up for about 2 days without crashing :) |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-10-29 by sameh.hady Great @d0773dm glad you sorted it out :) |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-12-11 by @gfwilliams WebSocket Server support now works! http://forum.espruino.com/conversations/278902/#comment12674947 @sameh.hady is there a reason that the |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-02-09 by pablorodiz Just in case anyone is interested on secure webSockets I have a rough implementation on GitHub (wss.js) based on the examples in this thread and the current ws module. It works with my server, but I would like to make some more testing and try to do the server part before asking for a pull request. By the way, I used a new module, wss.js, instead of modifying the current ws.js file since SSL/TLS is not available on all Espruino boards. But I can accept sugestions. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-02-11 by @gfwilliams Thanks! It seems a shame to have a duplicate of what's basically the same module though. I wonder whether it'd make more sense to just allow the existing WebSocket library to be used easily with a connection that was already established? After all, that's what |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-02-12 by Injecteer I'd like to use the wss for my client on ESP8266, but the require( 'tls' ) module can not be found... |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-02-13 by @gfwilliams
Looks like it should still work as long as you don't use the code in such a way that you're asking it to make a secure connection? But honestly the espruino-provided websocket code should work pretty well now? |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-02-13 by Injecteer If I try connecting to wss://myserver.com:8822:
I get
In the chrome ws-client the connection over wss:// is working. I have another SSL-free ws-endpoint on 8827 on my server, and it's working just fine in ESP. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-02-13 by @gfwilliams Well, since ESP8266 doesn't do SSL with Espruino it's hardly surprising it's complaining. If you had an Espruino WiFi or had an Espruino Pico with ESP8266 connected then SSL would work. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-02-13 by Injecteer I have a NodeMCU dev board with ESP8266 MOD (?) chip on it. Is it compatible with EspruinoWIFI? |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-02-13 by @gfwilliams
No. Espruino WiFi is a board itself - it's for an STM32 and a ESP8266 on it, so has more memory available for stuff like TLS. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-02-27 by mattbrailsford
Hi, I'm currently waiting for my espruino + CC3000 boards to arrive but one thing I would like to do when it does is connect to it over a WebSocket and was wondering a) if it would be possible to implement the WebSocket protocol on the Espruino? and b) whether anyone has actually done it? I basically want to be able to control servos and things over a WebSocket from a JS interface (hey, I know javascript, so want to use it :))
Any help appreciated.
Many thanks
Matt
Beta Was this translation helpful? Give feedback.
All reactions