Skip to content

Commit c8828f0

Browse files
committed
Updated for v1.0.0 release
1 parent c590279 commit c8828f0

File tree

2 files changed

+87
-5
lines changed

2 files changed

+87
-5
lines changed

README.md

Lines changed: 82 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,87 @@
1-
jsonet
1+
JavaScript Object Networking (jsonet)
22
======
33
[![Build Status](https://travis-ci.org/dotdecimal/jsonet.png?branch=master)](https://travis-ci.org/dotdecimal/jsonet)
44
[![Coverage Status](https://coveralls.io/repos/dotdecimal/jsonet/badge.png)](https://coveralls.io/r/dotdecimal/jsonet)
55

66
JavaScript Object Network messaging server/client for Node.js
7+
8+
This library provides a server and a socket class (with APIs that are very similar to the net package in Node.js) which communicate by sending each other JSON messages.
9+
10+
You "write" JSON objects to the socket, and the "message" events on the other end of the socket emits the JSON object you wrote.
11+
12+
## Installation
13+
14+
$ npm install jsonet
15+
16+
## Example
17+
18+
``` javascript
19+
var port = 8212;
20+
21+
// Create server
22+
var server = jsonet.createServer(function (socket) {
23+
24+
// Write messages received by server to console
25+
socket.on('message', function (message) {
26+
console.log(message);
27+
socket.write({
28+
boo: 'baz'
29+
});
30+
});
31+
});
32+
33+
// Listen to port
34+
server.listen(port, function () {
35+
36+
// Connect to server with new client socket
37+
var client = jsonet.createSocket();
38+
39+
// Write messages received by client to console
40+
client.on('message', function (message) {
41+
console.log(message);
42+
});
43+
44+
// Connect and write message to server
45+
client.connect(port, function () {
46+
client.write({
47+
foo: 'bar'
48+
});
49+
});
50+
});
51+
```
52+
53+
## Factories
54+
55+
### jsonet.createServer([options], [connectionListener])
56+
Creates a new TCP server. The ```connectionListener``` argument is automatically set as a listener for the 'connection' event.
57+
58+
See Node.js documentation for [net.createServer([options], [connectionListener])](http://nodejs.org/api/net.html#net_net_createserver_options_connectionlistener) for more details.
59+
60+
**TODO: Complete remaining Factory documentation**
61+
62+
## Server
63+
64+
### server.listen(port, [host], [backlog], [callback])
65+
Begin accepting connections on the specified ```port``` and ```host```. If the ```host``` is omitted, the server will accept connections directed to any IPv4 address (```INADDR_ANY```). A port value of zero will assign a random port.
66+
67+
Backlog is the maximum length of the queue of pending connections. The actual length will be determined by your OS through sysctl settings such as ```tcp_max_syn_backlog``` and ```somaxconn``` on linux. The default value of this parameter is 511 (not 512).
68+
69+
This function is asynchronous. When the server has been bound, 'listening' event will be emitted. The last parameter callback will be added as an listener for the 'listening' event.
70+
71+
One issue some users run into is getting ```EADDRINUSE``` errors. This means that another server is already running on the requested port. One way of handling this would be to wait a second and then try again.
72+
73+
See Node.js documentation for [server.listen(port, [host], [backlog], [callback])](http://nodejs.org/api/net.html#net_server_listen_port_host_backlog_callback) for more details.
74+
75+
**TODO: Complete remaining Server documentation**
76+
77+
## Socket
78+
79+
**TODO: Complete Socket documentation**
80+
81+
## Protocol
82+
83+
If you would like to implement the protocol yourself, the server will expect the following in order in the byte stream:
84+
85+
1. A 32-bit unsigned big-endian integer with 174021652 as the value. This is the protocol signature, if a message is sent without this signature a protocol error will be raised.
86+
2. A 32-bit unsigned big-endian integer with the length of the message being sent as the value.
87+
3. A UTF-8 string with the stringified JSON as the value (the message).

package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
{
22
"name": "jsonet",
3-
"description": "JavaScript Object Network messaging server/client",
4-
"version": "0.0.1",
3+
"description": "JavaScript Object Networking library for passing JSON messages between a server and client.",
4+
"version": "1.0.0",
55
"license": "MIT",
6-
"author": "Sal Gerace",
6+
"author": "Sal Gerace <sgerace@gmail.com>",
77
"keywords": [
88
"json",
99
"net",
1010
"tcp",
1111
"server",
1212
"client"
1313
],
14-
"repository": "git://github.com/sgerace/jsonet.git",
14+
"homepage": "https://github.com/dotdecimal/jsonet",
15+
"repository": "git://github.com/dotdecimal/jsonet.git",
1516
"engines": {
1617
"node": ">= 0.8.0"
1718
},

0 commit comments

Comments
 (0)