fast-websocket

0.0.3 • Public • Published

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();
});

Package Sidebar

Install

npm i fast-websocket

Weekly Downloads

1

Version

0.0.3

License

MIT

Unpacked Size

9.23 kB

Total Files

6

Last publish

Collaborators

  • lanmeng2022