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
Tobias Berger 97ab03c6b3
First pass
2022-02-28 12:07:38 +01:00

25 lines
591 B
JavaScript

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!");
});