ColdFusion Summit Notes - Refreshing your UI: Modern Uses for WebSockets, Giancarlo Gomez

October 15, 2018

websockets are:
full duplex communication channels over a TCP connection
bidirectional communication
little overhead
not holding an http connection open
very low latency

they are NOT:
push notifications like you see on your phone
web push notifications sent from a website via a Push Service

all of those take a lot of work to get set up compared to websockets

sockets
connected to the site
waiting for messages
better latency than push notifications

demo site: https://game.fusedev.com

Simon game
built in less than a day
uses web sockets to pass the data back and forth

in Application.cfc:
this.wschannels = [ { name: “demo” } ];
define the channels you’ll subscribe to

in the cfm files:
<cfwebsocket name=“ws” onmessage=“parseMessage” subscribeto=“demo”>

name=“ws” - creates JS variable you use to do the JavaScirpt manipulation
onmessage=“parseMessage” — run that function when you receive a message
subscribeto=“demo” - name of channel we’re interested in

requirements to run web sockets on CF —

1. use built in web socket server or the proxy
if internal, open up ports if you’re behind a firewall
default is 8575 and 8543
secure connections only supported on CF 11 and higher
if you have to support older browsers, it does a fallback using Flash (port 1243)
add certificates to a java Keystore or a pcks12 file

2. using proxy (recommended over the built in one)
ease of use
don’t have to open up any ports
IIS 8+ w/ WebSocket Protocol Enabled
uses ports 80 and 443 just like websites

Apache 2.2 compiled w/ worker module
Apache MPM Worker