socket.io-request
bidirectional request-response for socket.io
Feature
Of cource, Socket.IO's emit
and on
have request-response. This library adds some features.
- Promise interface
- Exception handling
timeout
disconnect
Install
% npm install socket.io-request -save
Methods
request("method", data)
returnPromise
response("method", handler)
Usage
request from Client to Server
client
var ioreq = ;var io = "http://localhost:3000"; io;
server
var ioreq = ;var io = 3000; io;
request from Server to Client
server
var ioreq = ;var io = 3000; io;
client (web browser)
var ioreq = ;var io = "http://localhost:3000"; io;
Error handling
res.error
returns error object to requester.
;
;
Options
var options = event: "socket.io-request" // event name on socket.io timeout: 90000 // request timeout (msec); ;
Async-Await
Using async-await syntax, you can write like below.
async { const res = await ;};
Samples
in ./sample
directory.
Develop
% npm i
% npm run build
% npm test