从HTML页面连接到coldfusion websocket [英] connect to coldfusion websocket from HTML page
问题描述
我想打开一个到ColdFusion 2016服务器的Web套接字,但我想从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网络套接字路径
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套接字对象上写下以下命令以订阅任何频道
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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!