WebSocket with Lucee and ColdFusion

WebSocket is a communication protocol which provides a full-duplex and low-latency channel between the server and the browser. More information can be found here. WebSocket offers a wide range of possibilities that you should use in your CFML application. There are several ways to implement this technology in your application, and for these options I have created some examples.

I will mainly focus on Lucee in this examples, thus this is the CFML engine I mostly use. Also, ACF natively supports WebSocket since version 10. So if you are in search for some resources regarding the usage and configuration for WebSockets in ACF, check out the following guides:

+ WebSocket Server Settings
+ Example from Adobe
+ WebSockets Enhancements

WebSocket Extension for Lucee

One way to get WebSocket running on Lucee, is to use the matching extension from Igal Sapir. There also exists a "Getting Started" video for the usage of this extension.

The latest version of the WebSocket extension needs some manual configuration in Tomcat. If you are running Lucee behind a Webserver like IIS, there is additional configuration needed.

Sadly, it seems that it is not possible to get this running in CommandBox with the latest version of the WebSocket extension, due to the manual configuration in Tomcat that is needed to get everything running properly. CommandBox does not use Tomcat and instead runs with undertow.

Information regarding this issue:
https://ortussolutions.atlassian.net/browse/COMMANDBOX-844
https://github.com/cfmlprojects/runwar/issues/144

If you want to get it working with CommandBox, you need to fall back to version 1.1.3.1 of the extension. This version doesn't need any additional configuration in Tomcat and thus also works with CommandBox. However, I did experience a lot of instabilities with this version of the extension. Getting it running consistently behind IIS was not possible. With the latest version, all these issues were eliminated. So I recommend using the latest version or try one of the alternatives like socket.IO.

Example with latest version of extension:

The repository from flowt-au already provides such an example, but lacks the automation of the configuration. Goal of this example is, to automate the complete setup and configuration of the extension.

GitHub - rabume/lucee-websocket
Contribute to rabume/lucee-websocket development by creating an account on GitHub.

Example with version that is compatible with CommanBox:

GitHub - rabume/commandbox-websocket
Contribute to rabume/commandbox-websocket development by creating an account on GitHub.

Socket.IO

If you are a JavaScript Developer, you are probably familiar with socket.IO. This library enables low-latency, bidirectional and event-based communication between a client and a server. It is built on top of the WebSocket protocol and provides additional guarantees like fallback to HTTP long-polling or automatic reconnection.

Introduction | Socket.IO
What Socket.IO is

Giancarlo Gomez held an awesome presentation about WebSocket and their implementation with ColdFusion. You can find all the demos shown in his presentation on his GitHub.

My own example is based on one of the demos from Giancarlo Gomez. I simple took only the needed resources and create a docker environment for it.

GitHub - rabume/cf-socketio
Contribute to rabume/cf-socketio development by creating an account on GitHub.