Skip to content
CometD.NET is a C# client library for the Bayeux protocol
Latest commit 0fcf58c Nov 5, 2011 @magnusga magnusga Merge pull request #11 from HakanL/master
Code improvements


CometD.NET is a project to provide an implementation of the Bayeux protocol in .NET. The client code is ported based on the source code from the java client found at You can also visit that page if you are looking for a CometD server.

This is the CometD.NET project home.

cometd/bayeux           - The Bayeux Specification
cometd/client 		- The .NET client library
cometd/common		- Classes from the java cometd common directory


The CometD.NET client won't work without a bayeux/cometd server to connect to. If you have installed the cometd server from, you should be able to connect to it.


The CometD.NET client library is set to compile with .NET Framework 3.5, and does not support .NET Framework Client Profile. If you get an error about a dependency on "System.Web.Extensions", you should go to your project properties and change to a framework without Client Profile.


Usage is basically the same as in the java-client ( HakanL have made a simple command-line tool which utilizes the basic functionality ( You can also look at to see how we use it to communicate with our own bayeux-server.


using Cometd.Client;
using Cometd.Client.Transport;
using Cometd.Bayeux;
using Cometd.Bayeux.Client;
using Cometd.Common;

        class Listener : IMessageListener
                public void onMessage(IClientSessionChannel channel, IMessage message)
                    // Handle the message

        static void Main(string[] args)
            // Handshake
            String url = "http://localhost:8080/cometd ";
            BayeuxClient client = new BayeuxClient(url, new List<ClientTransport>() { new LongPollingTransport(null) });
	    client.waitFor(1000, new List<BayeuxClient.State>() { BayeuxClient.State.CONNECTED });

            // Subscription to channels
            IClientSessionChannel channel = client.getChannel("/service/echo");
            channel.subscribe( new Listener() );

            // Publishing to channels
            Dictionary<String, Object> data = new Dictionary<String, Object>();
            data.Add("bar", "baz");

            // Disconnecting
	    client.waitFor(1000, new List<BayeuxClient.State>() { BayeuxClient.State.DISCONNECTED });

Something went wrong with that request. Please try again.