Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ilgooz/reqrepable-socket
Give request/respond capability to nodejs net package sockets
https://github.com/ilgooz/reqrepable-socket
Last synced: about 1 month ago
JSON representation
Give request/respond capability to nodejs net package sockets
- Host: GitHub
- URL: https://github.com/ilgooz/reqrepable-socket
- Owner: ilgooz
- Created: 2014-09-27T21:31:04.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2014-09-27T21:40:10.000Z (about 10 years ago)
- Last Synced: 2024-09-19T00:23:25.629Z (about 2 months ago)
- Language: JavaScript
- Size: 113 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# ReqRepable Socket
This module provides `socket.req()` and `socket.rep()` capabilities to your sockets.## Installation
```
npm install reqrepable-socket
```## Examples
**Server**
```javascript
var net = require('net');
var RRSocket = require('../');function connection(sock){
var socket = RRSocket(sock);socket.req('a message', {custom: 'test'}, function(answer){
// returns: 'i see that...'
console.log(answer);
});socket.rep('another message', function(a, b, reply){
// returns: 'hello', 'world'
console.log(a, b);
reply('ye so...');
});
};var server = net.createServer(connection);
server.listen(3000);
```**Client**
```javascript
var net = require('net');
var RRSocket = require('../');var socket = RRSocket(net.connect(3000));
socket.rep('a message', function(a, reply){
// returns: {custom: 'test'}
console.log(a);
reply('i see that...');
});socket.req('another message', 'hello', 'world', function(answer){
// returns: 'ye so...'
console.log(answer);
});
```