Created
January 30, 2024 19:41
-
-
Save lizzybrooks/24f5e1293ed3261e51a831327b3209fe to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var express = require ('express'); | |
const PORT = process.env.PORT || 3000; | |
var app = express(); | |
var server = app.listen(PORT, () => console.log(`Listening on ${PORT}`)); | |
app.use(express.static('public')); | |
console.log("my socket server is running"); | |
var socket = require ('socket.io'); | |
var io = socket(server); | |
io.sockets.on('connection', newConnection); | |
function newConnection(socket){ | |
console.log('new connection ' + socket.id); | |
socket.on('mouse', mouseMsg); | |
function mouseMsg(data){ | |
socket.broadcast.emit('mouse',data); | |
console.log(data) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment