Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/vilicvane/socket-jet
Minimalist package for data packets over socket connections.
https://github.com/vilicvane/socket-jet
Last synced: 20 days ago
JSON representation
Minimalist package for data packets over socket connections.
- Host: GitHub
- URL: https://github.com/vilicvane/socket-jet
- Owner: vilicvane
- Created: 2017-09-17T12:39:44.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2023-07-12T02:32:43.000Z (over 1 year ago)
- Last Synced: 2024-11-30T15:42:01.581Z (23 days ago)
- Language: TypeScript
- Size: 640 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
[![NPM Package](https://badge.fury.io/js/socket-jet.svg)](https://www.npmjs.com/package/socket-jet)
[![Build Status](https://travis-ci.org/vilic/socket-jet.svg)](https://travis-ci.org/vilic/socket-jet)# Socket Jet
Minimalist package for data packets over socket connections.
## Features
### Implemented
- `Jet#send()` returns a promise that will wait for ack.
- `PowerJet#call()` to call methods defined on a remote `PowerJet`.
- Encryption support based on Node.js `Cipher` and `Decipher`.## Installation
```sh
yarn add socket-jet
# or
npm install socket-jet --save
```## Usage
### Basic Jet
**Server**
```ts
let server = Net.createServer(socket => {
let jet = new Jet(socket);jet.on('data', data => {
console.log(data); // {thank: 'you'} from client.
});jet.send('hello').then(
() => console.log('"hello" sent'),
error => console.error(error),
);
});server.listen(10047);
```**Client**
```ts
let socket = Net.connect(10047, () => {
let jet = new Jet(socket);jet.on('data', data => {
console.log(data); // 'hello' from server.
});jet.send({thank: 'you'}).then(
() => console.log('data sent'),
error => console.error(error),
);
});
```### Power Jet
**Server**
```ts
class ServerPowerJet extends PowerJet {
async test(timeout: number): Promise {
return await new Promise(resolve => {
setTimeout(resolve, timeout, 'hello, jet!');
});
}
}let server = Net.createServer(socket => {
new ServerPowerJet(socket);
});server.listen(10047);
```**Client**
```ts
let socket = Net.connect(10047, () => {
// Note: Client can also have derived `PowerJet` with methods to be called by server.
let jet = new PowerJet(socket);jet.call('test', 1000).then(console.log); // 'hello, jet!' after 1000ms.
});
```### Encrypted Jet
**Server**
```ts
let server = Net.createServer(socket => {
let jet = new Jet(socket, {
crypto: {
algorithm: 'aes-256-cfb',
password: 'some password',
},
});jet.on('data', data => {
console.log(data); // {thank: 'you'} from client.
});jet.send('hello').then(
() => console.log('"hello" sent'),
error => console.error(error),
);
});server.listen(10047);
```**Client**
```ts
let socket = Net.connect(10047, () => {
let jet = new Jet(socket, {
crypto: {
algorithm: 'aes-256-cfb',
password: 'some password',
},
});jet.on('data', data => {
console.log(data); // 'hello' from server.
});jet.send({thank: 'you'}).then(
() => console.log('data sent'),
error => console.error(error),
);
});
```## License
MIT License.