So lets get familiar with the different ways to publish data.
- Publish from server: If you want to do a publish from ColdFusion server you need a CFML function, and that function is wsPublish.
Using ColdFusion Function:
Here is a sample code to publish a simple message from Server to the channel -publishdemochannel.
Instead of the simple message you can also publish different types of data, like array, struct and query using wspublish.
Wspublish("publishdemochannel","Welcome to publishdemochannel");
mycfwebsocketobject.publish("publishdemochannel","My test message to publishdemochannel" );
var myarr= new Array();
var myobj= new Object();
As I mentioned earlier invokeAndPublish is used to call a CFC function.The value returned by the function is published over the channel.
For example you have the employee id of the person, but you don't have the name of the person, you can use invokeAndPublish method of websocket to invoke the cfc method that will take the empid and will return the message that needs to be published.
The value that the fucntion returns will be published to the channel specified:
mycfwebsocketobject.invokeAndPublish("publishdemochannel", "employee", "processMessage",[389,"Hello "]);
public function processMessage(eid,msg)
//Write your logic to get the empname based on empid
return msg & " " & empname;
With the description here I hope you will be able to get started with your application to manage real time data. In the next few blogs I will try to explain more scenarios that you will come across in your ColdFusion WebSocket application development.
For more on How to handle responses from server checkout my next blog entry