connect to coldfusion websocket from HTML page(从 HTML 页面连接到coldfusion websocket)
问题描述
我想打开一个连接到 ColdFusion 2016 服务器的网络套接字,但我想从 HTML 页面(不是 cfm)打开它,所以我没有使用 cfwebsocket 标记的选项.我想要的是替代它..我试过下面的代码
I want to open a web-socket to a ColdFusion 2016 server, but I want to open it from HTML page (not cfm) so I don't have the option to use cfwebsocket tag. what I want is a replacement for it.. I have tried the following code
var webSocket_IP = '192.168.1.223';
var chatSocket = new WebSocket("ws://"+webSocket_IP+":8579/cfusion/cfusion");
chatSocket.onopen = function () {
alert('OPEN');
};
chatSocket.onmessage = function () {
alert('a message was recieved');
};
chatSocket.onError = function () {
alert('Error');
};
问题是我无法打开连接并且onOpen方法没有运行
the problem is that I cant open the connection and the onOpen method does not run
另一个问题是当我想订阅任何频道时
another problem is that when I want to subscribe to any channel
chatSocket.subscribeTo('chat');
我不断收到以下错误
TypeError: chatSocket.subscribeTo is not a function
推荐答案
如果有人遇到同样的问题,我已经找到了解决方案首先连接到coldfusion web socket路径
in case someone stumbled with the same issue , I have found the solution first connect to coldfusion web socket path
var chatSocket = new WebSocket("ws://"+webSocket_IP+":8579/cfusion/cfusion");
然后在web socket对象上写如下命令订阅任意频道
then write the following command on the web socket object to subscribe to any channel
{"ns":"coldfusion.websocket.channels","type":"welcome","subscribeTo":"CHANNELNAME","appName":"APPNAME"}
如果您想写消息,请使用以下内容:
and in case you want to write a message use the following:
{"ns":"coldfusion.websocket.channels","type":"publish","channel":"CHANNELNAME","data":"hi","appName":"APPNAME"}
这篇关于从 HTML 页面连接到coldfusion websocket的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:从 HTML 页面连接到coldfusion websocket
基础教程推荐
- 如何使用JIT在顺风css中使用布局变体? 2022-01-01
- 直接将值设置为滑块 2022-01-01
- Electron 将 Node.js 和 Chromium 上下文结合起来意味着 2022-01-01
- Chart.js 在线性图表上拖动点 2022-01-01
- html表格如何通过更改悬停边框来突出显示列? 2022-01-01
- 用于 Twitter 小部件宽度的 HTML/CSS 2022-01-01
- 如何使用TypeScrip将固定承诺数组中的项设置为可选 2022-01-01
- 自定义 XMLHttpRequest.prototype.open 2022-01-01
- 我可以在浏览器中与Babel一起使用ES模块,而不捆绑我的代码吗? 2022-01-01
- Vue 3 – <过渡>渲染不能动画的非元素根节点 2022-01-01