]> git.cworth.org Git - zombocom-ai/commitdiff
Make a socket connection from client to server
authorCarl Worth <cworth@cworth.org>
Wed, 7 Dec 2022 04:11:15 +0000 (20:11 -0800)
committerCarl Worth <cworth@cworth.org>
Wed, 7 Dec 2022 04:11:15 +0000 (20:11 -0800)
Nothing useful yet, just a print on the server side to prove it's working.

index.html
index.js

index 8eb3c6ac7c52d19a6ad66d8ef81286ce7f91c17a..5a74b471a44353b74de7cb0049532527be4453d1 100644 (file)
@@ -96,5 +96,10 @@ mute.addEventListener("click", () => {
     </button>
 
   </div>
+
+  <script src="/socket.io/socket.io.js"></script>
+  <script>
+    var socket = io();
+  </script>
 </body>
 </html>
index abacb5918e09342e14137eea94aad872c92f38b4..336f36ffd8fe0af1a610bfb406f92d498a505f46 100644 (file)
--- a/index.js
+++ b/index.js
@@ -2,12 +2,18 @@ const express = require('express');
 const app = express();
 const http = require('http');
 const server = http.createServer(app);
+const { Server } = require("socket.io");
+const io = new Server(server);
 const port = 2122;
 
 app.get('/index.html', (req, res) => {
     res.sendFile(__dirname + '/index.html');
 });
 
+io.on('connection', (socket) => {
+    console.log('a user connected');
+});
+
 server.listen(port, () => {
     console.log(`listening on *:${port}`);
 });