【发布时间】: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