Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <title>Socket IO Testing</title>
- </head>
- <body>
- <div>
- <h3>Request</h3>
- <span id="socketId"></span>
- </div>
- <div>
- <h3>Response</h3>
- <span id="responseText"></span>
- </div>
- <script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.0.4/socket.io.js"></script>
- <script>
- var socket = io.connect("https://host_name_here");
- socket.on('ConnectionEstablished', function(data) {
- document.getElementById("socketId").innerText = JSON.stringify({socketId:socket.id,text:"Socket Connected successfully"});
- document.getElementById("responseText").innerText = "";
- console.log("Connection established successfully");
- });
- socket.io.on("connect_error",function (err) {
- console.log("Connection Error : " + err);
- });
- </script>
- </body>
- </html>
- const express = require("express");
- const app = express();
- const socket-io = require('socket.io');
- app.use(express.static("index.html");
- const server = app.listen(8000,function () {
- log.info(`express server run on port 8000`);
- });
- const io = socket-io.listen(server);
- io.on("connection",function(){
- console.log("socket connection established ");
- });
Add Comment
Please, Sign In to add comment