raylib-wasm-transpiler/tools/js-class-c-struct-transpiler/test/test_server.js

26 lines
943 B
JavaScript

import LoginRequest from "./build/LoginRequest"
import LoginResponse from "./build/LoginResponse"
var decoder = new TextDecoder("utf-8");
var port = 8089;
var ws = require("ws");
var wss = new ws.WebSocketServer({ port: port });
console.log("WebSocket server listening on ws://localhost:" + port + "/");
wss.on("connection", function (ws) {
console.log("Client connected!");
ws.on("message", function (message, isBinary) {
if (!isBinary) {
var text = decoder.decode(new Uint8Array(message).buffer);
console.log("received TEXT: " + text.length + " characters:");
console.log(' "' + text + '"');
} else {
const entity = new LoginRequest({}, new Uint8Array(message));
console.log(entity.Login.Email);
console.log(entity.Login.Password);
const response = new LoginResponse({success: true});
ws.send(response.bytes, { binary: true }); // Echo back the received message
}
});
});