Advertisement
louissse

nodejs socket.io ws

Apr 25th, 2020
531
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var io = require('socket.io')(process.env.PORT || 3500);
  2. const fs = require('fs')
  3.  
  4. console.log('server has started');
  5.  
  6. io.on('connection', function(socket) {
  7.     console.log('Connection established');
  8.  
  9.     socket.on('disconnect', function() {
  10.         console.log('Connection closed');
  11.     });
  12.  
  13.     socket.on('version', function(){
  14.         fs.readFile('./version.dat', (f1_err, f1_data) => {
  15.         if (f1_err)
  16.         {
  17.          console.error(f1_err);
  18.          f1_data = 'ERROR';
  19.         }
  20.  
  21.  
  22.         socket.emit('version_response', {con1: f1_data.toString()});
  23.         console.log('Version Requested | Output: ' + f1_data.toString());
  24.         });
  25.     });
  26. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement