【问题标题】:HTML5 Websocket TCP Port ListeningHTML5 Websocket TCP 端口监听
【发布时间】:2021-06-02 00:17:33
【问题描述】:

我正在将桌面应用程序与我的 asp.net mvc 应用程序集成。桌面应用程序正在端口:10000 上发布我需要在浏览器中收听的数据。下面是代码:

<html>
   <head>
      
      <script type = "text/javascript">
         function WebSocketTest() {
            
            if ("WebSocket" in window) {
               alert("WebSocket is supported by your Browser!");
               
               // Let us open a web socket
               var ws = new WebSocket("ws://127.0.0.1:10000");
                
               ws.onopen = function() {
                  
                  // Web Socket is connected, send data using send()
                  ws.send("Message to send");
                  alert("Message is sent...");
               };
                
               ws.onmessage = function (evt) { 
                  var received_msg = evt.data;
                  alert("Message is received...");
               };
                
               ws.onclose = function() { 
                  
                  // websocket is closed.
                  alert("Connection is closed..."); 
               };
            } else {
              
               // The browser doesn't support WebSocket
               alert("WebSocket NOT supported by your Browser!");
            }
         }
      </script>
        
   </head>
   
   <body>
      <div id = "sse">
         <a href = "javascript:WebSocketTest()">Run WebSocket</a>
      </div>
      
   </body>
</html>

我面临的问题是当桌面应用程序在端口上发布数据时,连接终止并且我正在关闭消息连接。有什么帮助吗?

【问题讨论】:

    标签: javascript google-chrome websocket tcp


    【解决方案1】:

    查看您的代码,我没有看到您关闭与 ws 的连接的任何地方,所以我认为它是在向您发送消息后关闭连接的服务器。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-05-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-13
      • 1970-01-01
      • 1970-01-01
      • 2017-03-13
      相关资源
      最近更新 更多