I’m trying to use the websocket extension, but I get the error “Firefox cannot establish a connection with the server”. Here what I did and tried :
I installed Lucee WebSockets Extension 2.0.3 by Igal Sapir
I added the file servlet-filter-utils-1.1.1.jar in C:\lucee\tomcat\lib
I added the following code in web.xml in C:\lucee\tomcat\conf
<!-- Required for the Lucee WebSocket Extension !-->
<filter>
<filter-name>HttpSessionInitializerFilter</filter-name>
<filter-class>net.twentyonesolutions.servlet.filter.HttpSessionInitializerFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>HttpSessionInitializerFilter</filter-name>
<!-- modify url-pattern to match your websocket endpoints !-->
<url-pattern>/ws/*</url-pattern>
</filter-mapping>
I restarted Lucee
I installed the module WebSocket Protocol in IIS
I created a folder test in my website with the file echoListener.cfc with the onMessage function.
I created index.cfm in the folder with the following code :
<h1>WebSocket Echo Example</h1>
<cfscript>
var test = "";
endpoint = "/ws/echo";
listener = new EchoListener();
test = WebsocketRegister(endpoint, listener);
</cfscript>
<p class="mt2m">Server side code:
<p>
<code class="block"><cfset echo(htmlCodeFormat('
<cfscript>
endpoint = "/ws/echo";
listener = new EchoListener();
WebsocketRegister(endpoint, listener);
</cfscript>
'))></code>
<cfsavecontent variable="js">
<script type="text/javascript">
var endpoint = "<cfset echo(endpoint)>";
var protocol = (document.location.protocol == "https:") ? "wss://" : "ws://";
var url = protocol + document.location.host + endpoint;
var wsecho = new WebSocket(url);
var log = function(evt){ console.log(evt); }
wsecho.onopen = log;
wsecho.onmessage = log;
wsecho.onerror = log;
wsecho.onclose = log;
</script>
</cfsavecontent>
<cfset echo(js)>
<p class="mt2m">Below is the JavaScript code that was used to set up the <code>wsecho</code> client:
<code class="block"><cfset echo(htmlCodeFormat(js))></code>
<p class="mt2m">Open Developer Tools and send a test message using the <code>wsecho</code>
object, e.g.
<p>
<code class="block">
wsecho.send("Hello Lucee WebSockets at " + (new Date()).getTime());
</code>
<style>
code { background-color: #f0f0f0; white-space: pre-wrap; }
.block { display: block; }
.mt2m { margin-top: 2em; }
</style>
I just want to point out that you cannot call WebsocketRegister(endpoint, listener); more than once after your application starts up. You need to restart Lucee if you want to call it again. That code should be called in onApplicationStart() in your application.cfc file.
I do not have websockets running in IIS on development. I am using tomcat on port 8888 for development, and my websocket endpoints include the 8888 port. I do have IIS working in production and have it setup with ARR as described in the post that @martin referenced.
When websockets are not connecting, it’s possible that your websocket handler code is problematic. The way to debug is by logging everything. There’s no other way to see what’s going on other than to write log entries. If you need to dump data, use serializeJSON() to convert it to text.
I’m sadly overwhelmed at work now and don’t have time to test your solutions right away. Thank you very much for your time, it gives me hope that I can get this to work later. One thing is certain, when I have more time to spend on websockets, I will come back here to let you know the result, whether positive or negative.
Better late than never. Good news, especially for me! I followed the steps in both topics provided by @martin and Websockets now work perfectly on Lucee!
@TonyMonast - I am really glad that you have this up and running. We have recently put a websocket app (that uses Lucee and IIS) into production and it has been working smoothly so far.