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

26 lines
943 B
JavaScript
Raw Normal View History

2024-06-12 23:05:45 -04:00
import LoginRequest from "./build/LoginRequest"
import LoginResponse from "./build/LoginResponse"
2024-05-27 19:03:58 -04:00
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 {
2024-06-12 23:05:45 -04:00
const entity = new LoginRequest({}, new Uint8Array(message));
console.log(entity.Login.Email);
console.log(entity.Login.Password);
2024-06-12 23:05:45 -04:00
const response = new LoginResponse({success: true});
ws.send(response.bytes, { binary: true }); // Echo back the received message
}
});
});