knightfall22
9/3/2018 - 1:33 PM

server.js

const express = require('express'),
    socketIo = require('socket.io'),
    http = require('http');

let app = express(),
    server = http.createServer(app),
    io = socketIo(server)

app.use(express.static('./public'));

io.on('connection', (socket) => {
    console.log(`Client has connected`);

    socket.emit('newMessage', {
        from: 'The terminator',
        text: 'Hi Hal i am the Admin'
    })

    socket.on('clientMessage', function (message) {
        console.log(message);
    })

    socket.on('disconnect', function () {
        console.log('Server has Disconnected');
    })

})

server.listen(4000, () => {
    console.log(`server on port 4000`);
})