https://github.com/mrtcode/opstream
Wrap other transports to have a reliable packet stream
https://github.com/mrtcode/opstream
polling socket-io sockjs websocket
Last synced: 5 months ago
JSON representation
Wrap other transports to have a reliable packet stream
- Host: GitHub
- URL: https://github.com/mrtcode/opstream
- Owner: mrtcode
- License: mit
- Created: 2017-02-23T15:17:35.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2017-02-23T15:22:45.000Z (almost 9 years ago)
- Last Synced: 2025-08-14T05:25:42.351Z (5 months ago)
- Topics: polling, socket-io, sockjs, websocket
- Language: JavaScript
- Homepage:
- Size: 5.86 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# OpStream - wrap other transports to have a reliable packet stream
* Guarantees that packets are delivered in the right sequence
* Guarantees that each packet is delivered only one time
* Buffers packets if connection is lost
* Resends packets when connection is restored
* Pauses sending new packets if other endpoint is busy and don't acknowledge them
opstream.push() => opstream.send => socket.io(client) => socket.io(server) => opstream.recv => opstream.pop()
## Install
Browser
```html
```
Node.js or Browserify
```
npm install opstream
```
```js
var OpStream = require('opstream');
```
## Send and receive packets
```js
//A simple example how OpStreams are connected
var OpStream = require('./opstream');
var server = new OpStream;
var client = new OpStream;
// connect server and client op streams
server.send = function (data) {
setTimeout(function () {
client.recv(data)
}, 0);
};
client.send = function (data) {
setTimeout(function () {
server.recv(data)
}, 0);
};
//imitate client side
function clientThread() {
for (var i = 0; i < 100; i++) {
client.push('packet' + i);
}
}
//imitate server side
function serverThread() {
server.onReadable = function () {
var op;
while (op = server.pop()) {
console.log('server.pop()', op);
}
};
}
serverThread();
clientThread();
```
## Examples
[OpStream + Socket.io example](https://github.com/mrtcode/opstream-example-socket.io)