Comparing version 0.0.1 to 1.0.0
{ | ||
"name": "jsonsocket", | ||
"version": "0.0.1", | ||
"version": "1.0.0", | ||
"description": "JSON socket", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
"test": "make test" | ||
}, | ||
@@ -23,3 +23,10 @@ "repository": { | ||
}, | ||
"homepage": "https://github.com/smmoosavi/jsonsocket" | ||
"homepage": "https://github.com/smmoosavi/jsonsocket", | ||
"dependencies": { | ||
"debug": "^2.1.1" | ||
}, | ||
"devDependencies": { | ||
"chai": "^1.10.0", | ||
"mocha": "^2.1.0" | ||
} | ||
} |
# jsonsocket | ||
JSON socket | ||
Comming ... | ||
## Install | ||
``` | ||
$ npm install jsonsocket | ||
``` | ||
## Usage | ||
```js | ||
var JsonSocket = require('jsonsocket'); | ||
``` | ||
## Methods | ||
### `JsonSocket(ip, port)` | ||
Create new json socket from ip and port. | ||
```js | ||
var socket = new JsonSocket('127.0.0.1', 7000); | ||
``` | ||
### `JsonSocket(socket)` | ||
Create new json socket from existing`net.Socket` | ||
```js | ||
var net = require('net'); | ||
var server = net.createServer(function (con) { | ||
var socket = new JsonSocket(con); | ||
} | ||
``` | ||
### `write(data)` | ||
Send object over socket. | ||
```js | ||
socket.write({foo: 'bar'}); | ||
``` | ||
### `disconnect()` | ||
Destroy connection | ||
### `on(eventType, listener)` | ||
Inherited from `events.EventEmitter` | ||
## Events | ||
### connect | ||
Emitted when socket connected (only when you pass ip, port). | ||
### json | ||
Emitted when full json received. | ||
```js | ||
socket.on('json', function (json) { | ||
console.log(json); | ||
} | ||
``` | ||
### disconnect | ||
Emitted when disconnected. | ||
## Logging | ||
You can enable logging. [See more](https://github.com/visionmedia/debug) | ||
```bash | ||
# disabled logging | ||
node test.js | ||
# connect, disconnect log | ||
DEBUG=JsonSocket:connection node test.js | ||
# data log | ||
DEBUG=JsonSocket:data node test.js | ||
# all json socket logs | ||
DEBUG=JsonSocket:* node test.js | ||
``` | ||
## Protocol | ||
We send json objects over socket then write one `\0`. This is c/c++ friendly protocol. :smile: | ||
``` | ||
{"x": 3}\0null\0"Hi"\0[]\0 | ||
``` |
Sorry, the diff of this file is not supported yet
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Empty package
Supply chain riskPackage does not contain any code. It may be removed, is name squatting, or the result of a faulty package publish.
Found 1 instance in 1 package
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
6085
10
58
0
91
1
2
+ Addeddebug@^2.1.1
+ Addeddebug@2.6.9(transitive)
+ Addedms@2.0.0(transitive)