Josheir said:
I also have worked with Java and PHP and SignalR
I learned SignalR a little. It is for C# ASP.NET. Take WebSockets and Node.js/Express. You will have JavaScript only. See it is simple to connect a server and a client. Place this files in one directory like this:
my-game
---public/index.html
---app.js
- Install Node.js and “nodemon” (npm i nodemon -g)
- Go to “my-game” and run: nodemon app.js
- Open a browser tab and type: localhost:3000
- Open a browser console: Ctrl+Shift+J and you will see “connection”
app.js (Server)
const express = require("express");
const http = require("http");
const ws = require("ws");
const path = require("path");
const app = express();
app.use(express.static(path.join(__dirname, "./public")));
app.get("/", (req, res) => { res.sendFile(path.join(__dirname, "index.html")) });
const httpServer = http.createServer(app);
const wss = new ws.Server({ server: httpServer });
wss.on("connection", (wss) => { console.log("connected") });
const port = process.env.PORT || 3000;
httpServer.listen(port, () => { console.log("Server started. Port: ", port) });
public/index.html (Client)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<h1>Hello</h1>
<script>
const ws = new WebSocket("ws://localhost:3000");
ws.onopen =
() => {
console.log("connected");
}
</script>
</body>
</html>