Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var http = require('http');
- var fs = require('fs');
- var io = require('socket.io');
- var server = http.createServer(function(req,res){
- res.writeHead(200,{'Content-Type' : 'text/html'});
- fs.readFile('./index.html',function(err,content){
- res.end(content);
- });
- }).listen(8080);
- io = io.listen(server)
- io.sockets.on('connection',function(client){
- client.emit('connecte');
- });
- <html>
- <meta charset='utf-8'/>
- <head>
- <title>my first page</title>
- <script src="http://localhost:8080/socket.io/socket.io.js" ></script>
- </head>
- <body>
- <h1>It work</h1>
- </body>
- <script>
- var socket;
- socket = io.connect('http://localhost:8080');
- socket.on('connecte', function(){
- alert('You are connected');
- });
- </script>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement