You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
1.2 KiB

var express = require('express');
var http = require('http');
var io = require('socket.io');
var bodyParser = require('body-parser');
var app = express();
app.use(express.static('./public'));
//Specifying the public folder of the server to make the html accesible using the static middleware
var jsonParser = bodyParser.json()
// create application/x-www-form-urlencoded parser
var urlencodedParser = bodyParser.urlencoded({ extended: true })
// POST /login gets urlencoded bodies
var server = http.createServer(app).listen(8080);
console.log("Listening on port 8080");
console.log("Send jsons to /show please.")
//Server listens on the port 8124
io = io.listen(server);
/*initializing the websockets communication , server instance has to be sent as the argument */
io.sockets.on("connection",function(socket){
/*Associating the callback function to be executed when client visits the page and
websocket connection is made */
console.log("New Connection");
app.post('/show', urlencodedParser, function (req, res) {
res.send('200');
console.log("sending porcoddio");
socket.emit("message", "porcoddio");
});
});