How to Use FlyComet in a ASP .Net MVC3 project

There are three important steps of using FlyComet.

    1. Install and configure ActiveMQ on the PC/server where you want to run the publisher. Generally it is just a
      1. download
      2. Unzip
      3. Make sure your JAVA_HOME is set to the right folder
      4. run the ACTIVE_MQ_HOMEbinactivemq.bat
      5. or install the windows service and run the service
      6. You can access the service admin console at http://localhost:8161/admin

      You can find more information on how to install and run activemq at

    2. Create a Visual studio 2010 project FlyCometMVC3Sample and include the FlyComet.dll. Our sample is created as an Asp .net/MVC3 project.
    3. I’ve chosen the Razor template as it would create some initial pages.
    4. Download jquery version above 1.6.2 and include the <script src=”/Portals/0/@Url.Content(“~/Scripts/jquery-1.6.2.js”)” type=”text/javascript”></script> in your _Layout.cshtml page.

< li>Include the FlyComet.js and HashMap.js under FlyCometMVC3Sample/Scripts folder.

  • Add the following snippet in the header section of /Views/Home/Index page.
       ViewBag.Title = "My Comet Sample"; 
       <script src="/Scripts/HashMap.js" type="text/javascript">
       </script> <script src="/Scripts/FlyComet.js" type="text/javascript"></script> 
  • Add a textbox for entering the channel name, a subscribe button and a unsubscribe button along with the following script.
       <div> Channel ID: <input type="text" id="txtchannel" /> 
       <br /> <input type="button" id="cmdSubscribe" value="Subscribe" /> 
       <input type="button" id="cmdUnsubscribe" value="UnSubscribe" /> 
       </div> <script type="text/javascript"> 
       var flyComet = null; 
       var onMessageReceived = function (type, data) 
         alert("Received type:" + type +", data :"+ data); 
       cmdSubscribe.onclick() = function () 
     	var channelid = $("#txtchannel").val(); 
    	alert(channelid); flyComet.SubscribeToChannel(channelid, false); 
       cmd.onclick() = function() 
        var channelid = $("#txtchannel").val(); 
       $(function () 
        flyComet = $.FlyComet(onMessageReceived); 
  • Add an entry in the web.config for redirecting all the comet requests to our FlyCometHandler. This should go under < system.web > section for sites in IIS6.
     <add verb="*" path="/FlyCometHandler.ashx" type="FlyComet.FlyCometHandler" /> 
  • For IIS 7 and above this should go under < system.webserver > section as below.
     <add verb="*" name="FlyComet" path="/FlyCometHandler.ashx" type="FlyComet.FlyCometHandler" /> 
  • Add an entry to ignore the FlyCometHandler.ashx route by MVC. Add the following line in global.asax.cs
  • Run activemq server & Execute the project.
  • Load the http://project/home/index page. Click on the subscribe button. Please note that the “testchannel” value is already populated on the text box
  • Once you click, the FlyComet.js automatically subscribes to the channel.
  • Click on the http://localhost:8161/admin/topics.jsp and send the following message.
     {"Channel":"testchannel","MessageData":"First Message from FlyComet"}
  • The value will be populated under the “Received Data” section


Download the Flycomet project and the above sample from FlyComet Codeplex site. The project is not fully released yet. So please download from the Source Code section.