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


基础教程推荐
- jQuery File Upload - 如何识别所有文件何时上传 2022-01-01
- 如何使用 CSS 显示和隐藏 div? 2022-01-01
- WatchKit 支持 html 吗?有没有像 UIWebview 这样的控制器? 2022-01-01
- Node.js 有没有好的索引/搜索引擎? 2022-01-01
- 如何使用sencha Touch2在单页中显示列表和其他标签 2022-01-01
- 什么是不使用 jQuery 的经验技术原因? 2022-01-01
- Javascript 在多个元素上单击事件侦听器并获取目标 2022-01-01
- 每次设置弹出窗口的焦点 2022-01-01
- 为什么我在 Vue.js 中得到 ERR_CONNECTION_TIMED_OUT? 2022-01-01
- 如何在特定日期之前获取消息? 2022-01-01