有人知道CF10中的新websockets功能是否可以跨域和跨服务器使用吗?有没有人知道或者有一些示例代码可以做到这一点?我有一个简单的在线帮助聊天在我的应用程序上工作,但我想将它应用到其他网站,并有一个中央管理员聊天区,支持代理将与用户跨域互动。
发布于 2013-12-13 06:06:45
据我所知,他们没有。但是,您可以使用<cfhttp>
调用将发布消息的其他站点上的文件。这是我完成的。
创建名为socketPublisher.cfm的文件,并将其保存在无需登录即可访问文件的目录中。
socketPublisher.cfm
<cfparam name="Request.Attributes.msgType" default="newJob">
<cfparam name="Request.Attributes.channel" default="notify">
<cfparam name="Request.Attributes.Type" default="">
<cfoutput>
<cfswitch expression="#Request.Attributes.Type#">
<cfcase value="yourType">
<cfscript>
WSPublish('chat',{message: '', msgType: '#Request.Attributes.msgType#'});
</cfscript>
</cfcase>
<cfdefaultcase>
<cfscript>
WSPublish('#Request.Attributes.channel#',{message: '', msgType: '#Request.Attributes.msgType#'});
</cfscript>
</cfdefaultcase>
</cfswitch>
</cfoutput>
然后,在其他站点上的操作页面中,您将需要向该文件发出http请求。
actionPage.cfm
<cfhttp method="Post" url="#socketURL#/_scripts/socketPublisher.cfm">
<cfhttpparam type="URL" name="msgType" value="pendingFiles">
</cfhttp>
这应该就行了。
CF10 WSPublish
还有一个已知问题,当尝试从操作页面执行重定向时,它将更改CGI作用域导致错误。在找到更好的解决方案之前,我将使用此解决方案来解决该问题。
https://stackoverflow.com/questions/17048557
复制相似问题