fast-websocket
v0.0.3
Published
Mini websocket sdk
Downloads
1
Maintainers
Readme
fast-websocket
About
A concise websocket tool that can quickly create a server or client, supporting data requests like HTTP requests
How use
npm
npm i fast-websocket --save
yarn
yarn add fast-websocket -S
server example
const WS = require("fast-websocket");
let ws = new WS({ port: 90 });
ws.startServer();
ws.on("got", function (currClient, json) {
console.log("got", json);
json.data = new Date().toLocaleTimeString();
currClient.ws.send(JSON.stringify(json));
});
client example
let ws = new WS({ url: "ws://localhost:90" });
ws.connect();
async function main() {
let res = await ws.got({
way: "time",
action: "now",
});
console.log(res);
}
ws.on("open", function () {
main();
});