Oyatel / CometD.NET

CometD.NET is a C# client library for the Bayeux protocol
43 stars 34 forks source link

Handshake method with just timeout doesn't work #6

Closed HakanL closed 13 years ago

HakanL commented 13 years ago

It waits for either CONNECTING OR DISCONNECTED, but the proper state when handshake is complete is CONNECTED. I compared to the Java client and they too use CONNECTING, but I believe that's wrong. It works correctly for me when I change it to CONNECTED (and leave DISCONNECTED).

grEvenX commented 13 years ago

Hi HakanL. Thanks for your fixes and comments.

I have discussed this issue with Simone from the Java project. There is indeed a bug here since the state can go directly to connected and not through connecting. The fix will be to support all three states in the handshake in the waitFor.

There has been quite a few bug fixes to the Java version and we haven't been tracking them, Simone said that this issue should be fixed in the Java version. We will try to track the changes done in the Java version from when we did the port and apply the same fixes for the .NET version.

HakanL commented 13 years ago

Hi, but if we get CONNECTING, doesn't that imply that we will get CONNECTED after? In that case, isn't it more correct to wait on the final CONNECTED (and not exist handshake when it's in CONNECTING)?

grEvenX commented 13 years ago

Even though the service is not in CONNECTED state, the handshake is still considered to be completed. The waitFor states indicates what states to wait for in order to determine wether the handshake was sent correctly or not. There are other ways to check wether the service is connected or not (see the listeners that can be added through watching the channels _Channel_Fields.METAHANDSHAKE and _Channel_Fields.METACONNECT).

e.g.

client = new BayeuxClient(url, transports);
client.getChannel(Channel_Fields.META_HANDSHAKE).addListener(initListener);
client.getChannel(Channel_Fields.META_CONNECT).addListener(connectionListener);

Where the connectionLister could contain

public void onMessage(IClientSessionChannel channel, IMessage message)
        {
            if (message.Successful)
            {
                if (!connected)
                {
                    connected = true;
                    onConnected();
                }
            }
            else
            {
                if (connected)
                {
                    connected = false;
                    onDisconnected();
                }
            }
        }
HakanL commented 13 years ago

Ok, thanks, I didn't know handshake was considered completed even if the service wasn't connected. Will you commit a change for this, or do you want me to change my pull request to include the changes discussed here?