srnet v2.0.3
Send and Return NETwork Protocol 2.0
Changes from SRP/1.0
Operations
FIN=0,OP=0000000,DATA=Data
+-+-------+------------------------------+ |F| opcode| | |I| (7) | DATA | |N| OP | (128 bytes) | +-+-------+------------------------------+
FIN: 1 bit
If data is longer than 128 bytes, FIN must be 0 and send it once.
Opcode: 7 bit
- 0000000 ECHO
- 0000001 BROADCAST
0000010 WAIT
Wait by milliseconds.
0000011 DATE/TIME
Return date and time.
0000100 DISCONNECT
Disconnect from seever.
0000101 DISCOVER
Get IDs of all clients.
0000110 SEND
Send data to another client.
ID must be selected by DATA.
If you sent it, server will return
<ASK> SEND
, then you must send request for it.0000111 RECV
Send request to anther client.
ID must be selected by DATA.
If you sent it, server will return
<ASK> RECV
, then you must send request for it.
Usage of server
var express = require("express");
var app = express();
var srnet = require("srnet");
var srnet_server = srnet.server();
app.use(srnet_server);
app.listen();
Usage of client
var srnet = require("srnet");
var srnet_client = srnet.client("url");
Events of server and client:
- connection / connect
- disconnect (server)
data(client)
Receives processed data without first.
data(server)
Receives data from client.
rawData (client)
Receives all raw data without first.
allRawData (client)
Receives all raw data.
receive (client)
Receives processed data if data starts with "#" and data doesn't mean error.
error (client)
Receives error object if data starts with "#" and data means error.
unknown (client)
Receives processed data if data starts with "#" and data is returning unknown status code.
send / recv (client)
Receives processed data if client received
<ASK> SEND
or<ASK> RECV
.