https://github.com/averagemarcus/espruino-websocket
Crude websocket implementation for use on an Espruino
https://github.com/averagemarcus/espruino-websocket
Last synced: 10 months ago
JSON representation
Crude websocket implementation for use on an Espruino
- Host: GitHub
- URL: https://github.com/averagemarcus/espruino-websocket
- Owner: AverageMarcus
- Created: 2016-09-19T19:20:25.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2016-09-21T07:56:05.000Z (almost 10 years ago)
- Last Synced: 2025-02-12T11:24:29.795Z (over 1 year ago)
- Language: JavaScript
- Size: 12.7 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# :warning: Now available in the Espruino repo - please use that instead
---
## :skull: _Deprecated_
# espruino-websocket
Websocket implementation for use on an [Espruino](http://www.espruino.com/)
## About
A modified version of the current Espruino websocket module (https://github.com/espruino/EspruinoDocs/blob/master/modules/ws.js) hosted here until these changes are accepted into the main repo.
## Improvements
* Correctly handles connection upgrade without closing connection
* Allows sending messages longer than 127 chars
* Correctly generated a random Sec-WebSocket-Key
* Adds ability for connecting to a websocket on a subdirectory by passing in the path
* Added function to close websocket
* Handle packets that contain multiple frames
## How to use
```js
var WebSocket = require("https://github.com/AverageMarcus/espruino-websocket/blob/master/websocket.js");
var wifi = require("EspruinoWiFi");
function onInit() {
wifi.connect(WIFI_NAME, WIFI_OPTIONS, function(err) {
if (err) {
return console.log("Connection error: "+err);
}
console.log("Connected to WiFi!");
var ws = new WebSocket('echo.websocket.org');
ws.on('open', function(msg) {
console.log('Connected', msg);
ws.send('Hello WebSocket!');
});
ws.on('message', function(msg) {
console.log('Message', msg);
});
});
}
onInit();
```