diff --git a/README.md b/README.md index d71a5d0..2cbe363 100644 --- a/README.md +++ b/README.md @@ -44,4 +44,36 @@ socket.on("open", (event) => { // close socket and disable auto-reconnect socket.close() +``` + +## Server + +The "SmartWebSocketServer" is far less sophisticated and simply introduces the events to the server side + +```js +const { WebSocketServer } = require('ws'); + +// module only exports function to upgrade existing websocketserver +const upgradeWSS = require('../SmartWebSocketServer.js'); + +const wss = new WebSocketServer({ port: 8082 }); + +// very first thing to call after creating websocketserver +upgradeWSS(wss); + +wss.on("connection", (ws) => { + console.log("connected"); + + // sending events to clients + ws.sendEvent("test", { "abc" : 123 }); + + // receiving events from clients + ws.on("test2", (data) => { + console.log(data); + }); +}); + +wss.on("listening", () => { + console.log("listening..."); +}) ``` \ No newline at end of file