Guest User

Untitled

a guest
Mar 22nd, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Socket IO Testing</title>
  6. </head>
  7. <body>
  8.  
  9. <div>
  10. <h3>Request</h3>
  11. <span id="socketId"></span>
  12. </div>
  13. <div>
  14. <h3>Response</h3>
  15. <span id="responseText"></span>
  16. </div>
  17. <script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.0.4/socket.io.js"></script>
  18. <script>
  19. var socket = io.connect("https://host_name_here");
  20. socket.on('ConnectionEstablished', function(data) {
  21. document.getElementById("socketId").innerText = JSON.stringify({socketId:socket.id,text:"Socket Connected successfully"});
  22. document.getElementById("responseText").innerText = "";
  23. console.log("Connection established successfully");
  24. });
  25.  
  26. socket.io.on("connect_error",function (err) {
  27. console.log("Connection Error : " + err);
  28. });
  29. </script>
  30. </body>
  31. </html>
  32.  
  33. const express = require("express");
  34. const app = express();
  35. const socket-io = require('socket.io');
  36.  
  37. app.use(express.static("index.html");
  38. const server = app.listen(8000,function () {
  39. log.info(`express server run on port 8000`);
  40. });
  41. const io = socket-io.listen(server);
  42. io.on("connection",function(){
  43. console.log("socket connection established ");
  44. });
Add Comment
Please, Sign In to add comment