1
Fork 0
This repository has been archived on 2022-08-23. You can view files and clone it, but cannot push or open issues or pull requests.
web-drs-frontend/echo-server.mjs

26 lines
591 B
JavaScript
Raw Normal View History

2022-01-07 14:46:33 +01:00
import { WebSocketServer } from "ws";
const port = 8989;
const wss = new WebSocketServer({ port: port });
console.log("listening on port: " + port);
wss.on("connection", function connection(ws) {
ws.on("message", function (message) {
console.log("message: " + message);
ws.send(
JSON.stringify({
date: Date.now(),
author: "ECHO Service",
content: message.toString("utf-8"),
})
);
});
ws.on("close", function close() {
console.log("closed a connection");
});
console.log("new client connected!");
ws.send("connected!");
});