0

如何使用 Socket.io CDN 直接转换成 HTML 即单机版。

检查源

<html>

<head>
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no">
    <meta charset="utf-8">
    <title>Get Data</title>
    <script src="http://137.184.61.204:3000/socket.io/socket.io.js"></script>
    <!-- <script src="http://localhost:3000/socket.io/socket.io.js"></script>  -->
</head>

<body>
    <div id="results"> This text will change </div>
    <div id="date">sample another temp text</div>
    <script>
        // client code here
        // let io = require("socket.io-client");
        var socket = io.connect('http://137.184.61.204:3000');
        socket.on('message', function (message) {
            console.log(message)
            document.getElementById("date").innerHTML = "My new text!";
        });

        // var socket = io.connect('localhost:3000');
        // socket.on('send-msg', function(message) {
        // console.log(message)
        //   document.getElementById("date").innerHTML = "My new text!";
        // });
        socket.on('welcome', function (data) {
            document.getElementById("results").innerHTML = data.message;
        });
    </script>
</body>

</html>

结果,我得到结果套接字已连接:false & connected:TRUE

我已经为源检查添加了带有标题的图像链接以供参考

4

0 回答 0