Advertisement
Guest User

Untitled

a guest
Jul 18th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const app = require('express')();
  2. const http = require('http').Server(app);
  3. const io = require('socket.io')(http);
  4.  
  5. app.get('/ping', function(req, res){
  6.   res.send('pong');
  7. });
  8.  
  9. io.on('connection', function(socket){
  10.   console.log("Client connected...");
  11.   socket.on('serverMessage', function(data) {
  12.     console.log("Incomming message", data);
  13.  
  14.     // sending to all clients except sender
  15.     socket.broadcast.emit('clientMessage', data);
  16.   })
  17. });
  18.  
  19. http.listen(1337, function(){
  20.   console.log('listening on *:1337');
  21. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement