Software Development, Web Design, Training

Apr-11-2019

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

what websockets are -
full-dpluex communication channels over a single TCP connection
bi-directional communication between client and server
little overhead
very little latency
event driven web programming, not just user initiated
stateful
can communicate with any # of them at any given time

what they are NOT
push notifications
- most of those are Google Cloud Messaging (GCM) or Apple Push Notifications (APNs)
web push notifications
push notifications are messages sent from a website via a Push Service

game.fusedev.com - demo app for the session

in app.cfc
this.name = “app name”
this.wschannels = { name: “demo” }
array of structures
need the “name” at a minimum

<cfwebsocket> tag in your index.cfm file

<cfwebsocket name=“ws” onmessage=“parseMessage” subscribeto=”demo”>
parseMessage(message) is a javascript function to handle the message, update website, etc.

in broadcast.cfm
WSpublish() to send message to clients

WSGetAllChannels() to get all the subscribers to a channel

requirements—
2 ways to use it
using build in websocket server
required if server does not meet minimum criteria to use the proxy version or if you’re working w/ clusters
Open some ports for secure and nonsecure: 8575 and 8543
secure is only supported on CF 11 and higher

Using Proxy

Recommended for ease of use / config
IIS8+ w/ web socket protocol enabled
Apache 2.2+ compiled w/ worker module, not prefork
(prefork is the default build)
Apache MPM Worker

where are these settings?
CF Admin - Server Settings - WebSocket
CF Admin - Data Services - Flex Integration
(instance)/lib/neo-websocket.xml
(instance)/bin/wsproxyconfig
IIS Site - cfws (virtual app under your site, there’s an app pool for this)
config/wsproxy/(site)/bin/config.ini

things to watch for -
App Pool must have a .net Framework assigned (4+)
IIS Proxy Mode - do not set it to “unmanaged code” or “.net 2”

Virtual app must have the same app pool assigned
IIS Proxy Mode - Pre CF 2018:
/cfusion/bin/wsproxyconfig always sets to default app pool even tho your parent website is a DIFFERENT app pool, which causes an error
make sure you have a specific user for your app pool and use the same one here
(fixed in CF 2018 first build, but maybe broke again in a recent patch, the bug has been reported)

if you add a new TOP level channel, have to restart CF for it to work.
any sub-level channel can be created in real time using dot notation (demo.room1, demo.room2, etc)
don’t have to do anything in CF for those to work

if you’re using the “proxy” method make sure the CFwebsotkcet tags don’t have the “secure” attribute set to “true”
for some reason this bombs out on SSL sites in proxy mode

Wrap wsPublish() in its own thread, especially if you’re in a framework.

real world issues —
network connections
need to account for wifi connection being dropped, reconnecting, etc.

AdvancedSocket
JavaScript lib created by Giancarlo
easily let’s you  integrate w/ cfwebsocket
callbacks for connection drops, easily lets you add notifications for users
application reinit
server downtime
network connection
automatically reconnects to subscribed channels