1. Prerequisites
We will be using CommandBox to spin up a server and install the Socket.io-lucee library. If you haven’t already, head over to the CommandBox installation guide and get it installed.
Note: it is possible to complete this tutorial with any other method of installing the library and starting a Lucee server - we just find this way to be the most convenient.
Once you have CommandBox installed and working, create an empty directory for this tutorial, and install this library:
mkdir -p ~/lucee-socket-io-tutorial
cd ~/lucee-socket-io-tutorial
box install socketiolucee
Next, add the two files below to the root of the directory:
Application.cfc
component {
this.name = "socket.io-lucee tutorial";
processingdirective preserveCase="true";
public void function onRequest( required string requestedTemplate ) output=true {
include template=arguments.requestedTemplate;
}
}
index.cfm
<!DOCTYPE html>
<html>
<head>
<title>Socket.io-Lucee: Tutorial</title>
<script src="https://cdn.socket.io/socket.io-2.3.1.js"></script>
</head>
<body>
</body>
</html>
Finally, startup your Lucee application using the box start
command in your terminal.
Note: We’re adding
--console
to the command so that we can easily trace background messages to demonstrate activity.
cd ~/lucee-socket-io-tutorial
box start --console
This should start the server and open up a browser window loading our index.cfm
file (an empty HTML page). We’re all set!
Next: 2. Making a connection