• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

CF2021 Getting Started with WebSockets (cfwebsocket)

New Here ,
Mar 28, 2022 Mar 28, 2022

Copy link to clipboard

Copied

Hello all:

 

I am just getting started with cfwebsockets and I am having a bit of trouble. What I found from online, is that since this is public-facing application, it is best to use a websocket proxy.

 

CF2021, Version: 2021.0.03.329779

Ubuntu 20.04LTS

 

Steps so far:

1. I added the websocket package to my server and enabled web-sockets. Restarted Server.

2. Added this to my application.cfc:

 

 

<cfset this.wschannels = [ {name="chat"} ] />

 

(the application has a this.name= set from a variable as well
3. created a simple page that has this:

 

<cfwebsocket 
name="wSocketObj" 
onMessage="wsOnMessage" 
onOpen="wsOnOpen" 
onClose="wsOnClose" 
onError="wsOnError" 
subscribeTo="chat"
secure="true"/>

<script type="text/javascript">
wsOnMessage =  function(aEvent,aToken) {
  console.log('wsOnMessage',aevent);
  var message = ColdFusion.JSON.encode(atoken); 
  var txt=document.getElementById("myDiv"); 
  txt.innerHTML +=message +"<br>"; 
}

wsOnOpen = function() {
  alert("wsOnOpen Connection is open");
}

wsOnClose = function() {
  alert("wsOnClose Connection Closed");
}

wsOnError = function() {
  alert("wsOnError!");
  console.log(arguments);
}

sendMessage = function() {
  var text = window.prompt("Enter some text","");
  if (text) {
    wSocketObj.publish("chat", text);
  }
}
</script> 
 
<cfdiv id="myDiv"></cfdiv>
<div id="myChatArea"></div>
<input type="text" id="myMessage" /><input id="myButton" type="button" value="Send Message" onClick="sendMessage()" />

 

3. got this in the Chrome Console:

 

WebSocket connection to 'wss://myhost.mydomain.com:8555/cfusion/cfusion' failed: 
CFWebSocketWrapper.open @ cfwebsocketCore.js:21
init @ cfwebsocketChannel.js:49
_cf_websockets_init_6322652258206397 @ client.cfm:35
fire @ cfajax.js:1214
$E.windowLoadHandler @ cfajax.js:1321
cfwebsocketCore.js:54 Uncaught TypeError: Cannot set properties of undefined (setting 'readyState')
at WebSocket.wsConnection.onerror (cfwebsocketCore.js:54:29)

 

thinking it was a firewall issue, I disabled it in Ubuntu

4. It was at this point that it seemed to be that I needed to configure a proxy.

5. I ran /opt/ColdFusion/cfusion/bin/wsproxyconfig.sh from the command line and verified that both the line in apache2.conf was there and the folder "/opt/ColdFusion/config/wsproxy/1/mod_wsproxy.conf" was created. Restarted apache2 and CF2021

6. Same Result

7. Realized I need to change the websocket config in CF Admin,

8. When I select the Use Proxy in CF Admin, the Save Changes button disappears and I cannot save it.

 

Obviously I am missing something very fundemental here. Any help that anyone can provide would be appreciated.

 

thanks in advance

Art

Views

233

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
no replies

Have something to add?

Join the conversation
Resources
Documentation