Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bcoin-org/bsock
Minimal implementation of the socket.io protocol.
https://github.com/bcoin-org/bsock
Last synced: 6 days ago
JSON representation
Minimal implementation of the socket.io protocol.
- Host: GitHub
- URL: https://github.com/bcoin-org/bsock
- Owner: bcoin-org
- License: other
- Created: 2017-10-18T16:32:26.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2023-10-31T09:17:45.000Z (about 1 year ago)
- Last Synced: 2024-11-05T01:06:41.955Z (8 days ago)
- Language: JavaScript
- Size: 381 KB
- Stars: 9
- Watchers: 10
- Forks: 7
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# bsock
A minimal websocket-only implementation of the socket.io protocol, complete
with ES6/ES7 features.## Usage
``` js
const http = require('http');
const bsock = require('bsock');
const io = bsock.createServer();
const server = http.createServer();io.attach(server);
io.on('socket', (socket) => {
// Bind = listen for event
socket.bind('bar', (data) => {
console.log('Received bar: %s.', data.toString('ascii'));
});
// Hook = listen for call (event + ack)
socket.hook('foo', async () => {
return Buffer.from('bar');
});
});server.listen(8000);
const socket = bsock.connect(8000);
socket.on('connect', async () => {
console.log('Calling foo...');
// Call = emit event and wait for ack
const data = await socket.call('foo');
console.log('Response for foo: %s.', data.toString('ascii'));
console.log('Sending bar...');
// Fire = emit event
socket.fire('bar', Buffer.from('baz'));
});
```## Contribution and License Agreement
If you contribute code to this project, you are implicitly allowing your code
to be distributed under the MIT license. You are also implicitly verifying that
all code is your original work. ``## License
- Copyright (c) 2017, Christopher Jeffrey (MIT License).
See LICENSE for more info.