javascript - Create room socket io -
i'm trying create simple node app if user press button called 'create room', room created, creator of room joins , make room available other players join limit of users. got far (i'm beginner sockets..)
///server side
const app = require('express')(); const io = require('socket.io')(); app.get('/', (req, res) => res.sendfile(__dirname + '/index.html')) io.on('connection', socket => { socket.on('create', room => socket.join(room) ) }) app.listen(3000, (req, res) => console.log('server up!'))
///client side
<!doctype html> <html> <head> <title>flip</title> <script src="https://cdn.socket.io/socket.io-1.4.5.js"></script> <script src="http://code.jquery.com/jquery-1.11.1.js"></script> </head> <body> <button>create room!</button> </body> <script type="text/javascript"> let socket = io.connect(); $('button').click(() => { socket.emit('create', 'room1') }) </script> </html>
Comments
Post a Comment