Advertisement
Guest User

Untitled

a guest
Oct 25th, 2014
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. var http = require('http');
  2. var fs = require('fs');
  3. var io = require('socket.io');
  4.  
  5. var server = http.createServer(function(req,res){
  6. res.writeHead(200,{'Content-Type' : 'text/html'});
  7. fs.readFile('./index.html',function(err,content){
  8. res.end(content);
  9. });
  10.  
  11. }).listen(8080);
  12.  
  13. io = io.listen(server)
  14.  
  15. io.sockets.on('connection',function(client){
  16.  
  17. client.emit('connecte');
  18.  
  19. });
  20.  
  21. <html>
  22. <meta charset='utf-8'/>
  23. <head>
  24. <title>my first page</title>
  25. <script src="http://localhost:8080/socket.io/socket.io.js" ></script>
  26. </head>
  27. <body>
  28. <h1>It work</h1>
  29. </body>
  30. <script>
  31. var socket;
  32.  
  33. socket = io.connect('http://localhost:8080');
  34.  
  35. socket.on('connecte', function(){
  36. alert('You are connected');
  37. });
  38.  
  39. </script>
  40. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement