Lets you create the WebSocket object in your CFM template.
Lets you create the WebSocket object in your CFM template. The tag creates a reference to the WebSocket JavaScript object at the client-side.
Example
In the following example,
- The user is automatically subscribed to the stocks channel.
- You have specified the channel name in the Application.cfc.
- The example uses the default channel listener.
In the Index.cfm, you specify the channels to which the user can automatically subscribe to (using the attribute subscribeTo) and also define the message handler.
Application.cfc
{
this.name="websocketsampleapp1";
this.wschannels=[{name="stocks"}];
}
Index.cfm
<script type="text/javascript">
function mymessagehandler(aevent, atoken)
{
var message = ColdFusion.JSON.encode(atoken);
var txt=document.getElementById("myDiv");
txt.innerHTML +=message +"<br>";
}
</script>
<cfwebsocket name="mycfwebsocketobject" onmessage="mymessagehandler" subscribeto="stocks" >
<cfdiv id="myDiv">
</cfdiv>
The code creates a JavaScript WebSocket object named mycfwebsocketobject. If the server sends a message, it calls mymessagehandler function.Since you have specified subscribeTo in the cfwebsocket tag, the WebSocket object automatically subscribes you to the channel stocks.
https://learn.adobe.com/wiki/display/coldfusionen/cfwebsocket