const express = require('express')
const Primus = require('primus')
const pathUtil = require('path')
const app = require('express')()
const server = require('http').createServer(app)
const primus = new Primus(server, { transformer: 'websockets' })
app.get('/', function (req, res) {
require('fs').createReadStream(pathUtil.join(__dirname, 'socket-client.html')).pipe(res)
app.use(function (req, res) {
res.status(404).send('404 Not Found. 🙁 \n')
primus.on('connection', function (spark) {
console.log('connection has the following headers', spark.headers)
console.log('connection was made from', spark.address)
console.log('connection id', spark.id)
spark.on('data', function (message) {
console.log('connection', spark.id, 'sends', message.toString())
process.stdin.on('data', function (message) {
spark.write('The server has spoken: ' + message.toString())
spark.write('Hello user. I am the server communicating to you.')