Created
December 13, 2024 00:03
-
-
Save lizzybrooks/b02f94f14b64f4ecf680ede53ff821ba to your computer and use it in GitHub Desktop.
This file contains hidden or 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('planePosition', planeMsg); | |
function planeMsg(position) { | |
socket.broadcast.emit('planePosition', position); | |
console.log('Broadcasting plane position:', position); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment