-
-
Save wyntonfranklin/a17cfac38faf1fff9d347781addb8498 to your computer and use it in GitHub Desktop.
App.js file that runs the server.
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'); | |
var path = require('path'); | |
var app = express(); | |
var server = require('http').Server(app); | |
var io = require('socket.io')(server); | |
var port = 8080; | |
app.use(express.static(path.join(__dirname, "public"))); | |
io.on('connection', function(socket) { | |
console.log('new connection made'); // send to the output | |
socket.emit('message-from-server', { | |
greeting: 'Hello from Server' | |
}); | |
socket.on('message-from-client', function(msg) { | |
console.log(msg); | |
socket.broadcast.emit('broadcast-to-client',{ message: msg.message }); | |
}); | |
}); | |
server.listen(port, function() { | |
console.log("Listening on port " + port); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment