Created
          December 21, 2017 03:00 
        
      - 
      
- 
        Save ynx0/0913d316664f48bcd20113f8d6fc0002 to your computer and use it in GitHub Desktop. 
    socket.io problem
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <meta charset="utf-8" /> | |
| <title>Socket.io</title> | |
| <script src="/jquery/dist/jquery.min.js"></script> | |
| <script src="/socket.io-client/dist/socket.io.js"></script> | |
| </head> | |
| <body> | |
| <h1>Communicating with socket.io!</h1> | |
| <p><input type="button" value="Poke the server" id="poke"/></p> | |
| <script> | |
| var socket = io(); | |
| var username = prompt('What\'s your username?') | |
| socket.emit('usr', username) | |
| socket.on('message', (message) => { | |
| alert('[@]' + message) | |
| }) | |
| $('#poke').click(function () { | |
| socket.emit('message', 'Hi server, how are you?'); | |
| }) | |
| </script> | |
| </body> | |
| </html> | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | 'use strict'; | |
| const path = require('path'); | |
| const express = require('express'); | |
| const app = express(); | |
| const server = require('http').createServer(app); | |
| const io = require('socket.io').listen(server) | |
| app.use(express.static('node_modules')) | |
| app.get('/', function(req, res, next) { | |
| res.sendFile(__dirname + '/index.html') | |
| }) | |
| io.on('connection', (socket) => { | |
| console.log('socket') | |
| }) | |
| app.listen(80) | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment