Entries Tagged as 'WebSocket'

The new WebSocket feature in ColdFusion 10 is useful in many scenarios. One such usecase is pushing server statistics to client applications.

This ColdFusion Builder extension  uses WebSocket feature of ColdFusion 10 to display two server stats - heap and CPU usage. It uses point-to-point (instead of publish-subscribe) mode of WebSocket communication. Once websocket is opened (using cfwebsocket tag), it invokes a method on CFC, that starts a thread and pushes server data to the client every 5 seconds using WebSocket API, wsSendMessage.

The client plots this data as graphs and updates them whenever new data is avilable from the CFC (which is every 5 seconds). It (client) keeps buffer of 200 readings and when it exceeds this limit, it compacts the array by merging some of the earlier readings. Here is a screen shot of this extension -

Screenshot - Server Stats Extension

Hovering mouse over the graph shows stats at that time. Note that this data is interpolated from nearby values. The CPU usage graph could be little misleading. It might appear that server is using CPU cycles all the time. But, since the CFC that sends this stats also run on the same server, some CPU cycles would be used by the script. And the graph is plotted by filling the area between current and previous readings. However this graph could be useful in observing change in CPU usage over a period of time.

Non-extension version of this tool is also available. Download this file, unzip it in the wwwroot and run index.cfm.

-Ram Kulkarni

 

The most vital part of ColdFusion WebSocket feature is the ability to push live data. You can publish data either from server to mulitple clients or from one client to multiple clients. ColdFusion Websockets provides you different methods , that could be used to publish data. Lets try to find out how these different methods are used.

In most real world applications data may not be very simple text. It could be complex arrays and structs. In such cases how do I make use of Coldfusion WebSocket JavaScript methods?. 

Here is my blogpost on different ways to publish data using ColdFusion WebSocket. Checkout the application provided which will help you get started with ColdFusion WebSocket implementation.

-Evelin Varghese

If you have downloaded ColdFusion Builder 2.0.1 beta and want to know how to use WebSocket feature in the ColdFusion 10, then this extension might help.

What this extension does

  • Briefly describes what Websocket is
  • Explains WebSocket support in ColdFusion 10
    • Settings in application.cfc
    • cfwebsocket tag
    • JavaScript callback functions
    • APIs to publish from JavaScript and CFML
    • websocketObj.Invoke method from JavaScript to invoke a method on CFC 
  • Generates demo files with inputs provided by you
  • Lets you lauch demo application from the extension.
Once you install this extension, right click on a folder in Navigator window where you want to generate demo code. You will see menu 'WebSocket Demo Ext'->'Create Demo' menu. Clicking on this menu will launch a new view in the right-bottom corner.

If you want to launch the demo from extension, make sure that the folder you select to generate demo code is in wwwroot of the server. 

Note that this extension works only on ColdFusion 10

-Ram Kulkarni

Update : This extension did not work on Mac. Fixed the issues and updated it.