Skip to content

Instantly share code, notes, and snippets.

@ynx0
Created December 21, 2017 03:00
Show Gist options
  • Save ynx0/0913d316664f48bcd20113f8d6fc0002 to your computer and use it in GitHub Desktop.
Save ynx0/0913d316664f48bcd20113f8d6fc0002 to your computer and use it in GitHub Desktop.
socket.io problem
<!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>
'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