https://github.com/json2d/kneesock
a simple pub sub wrapper for websockets/ws
https://github.com/json2d/kneesock
Last synced: 3 months ago
JSON representation
a simple pub sub wrapper for websockets/ws
- Host: GitHub
- URL: https://github.com/json2d/kneesock
- Owner: json2d
- Created: 2015-11-22T04:11:44.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2017-03-20T15:17:54.000Z (over 8 years ago)
- Last Synced: 2025-02-07T04:42:07.862Z (5 months ago)
- Language: JavaScript
- Size: 7.81 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# kneesock
*by Jason Yung - [http://callmejay.com](http://callmejay.com "http://callmejay.com")*a simple pub sub wrapper for websockets/ws
### Installing
$ npm install --save kneesock
### Basic Usage
```javascript
var KneeSock = require('kneesock')
var kneesock = new KneeSock({}, function onConnect(clientSpace) {kneesock.subscribe('chatroom', clientSpace);
kneesock.publish('chatroom', "alert to all, a new client has subscribed" })
clientSpace.client.on('message', function incoming(message) {
console.log('received: %s', message);kneesock.publish('chatroom', message)
});
});
```
### Using With Express
```javascript
var express = require('express')
, app = express()
, port = 4080app.get('/', function (req, res) {
res.render('chatroom');
}var KneeSock = require('kneesock')
var kneesock = new KneeSock({app:app, port:port}, function onConnect(clientSpace) {
...
});kneesock.server.http.listen(port, function () { console.log('Listening on ' + port) });
```
### Demos
To check out an example of a basic chatting service, run the command:$ node demo/chatroom.js
This will run the demo locally at http://localhost:4080