Code-Sharp / WampSharp

A C# implementation of WAMP (The Web Application Messaging Protocol)
http://wampsharp.net
Other
385 stars 84 forks source link

WampSharp Monitor not sense router-side channel close #217

Closed andeb91 closed 7 years ago

andeb91 commented 7 years ago

The WampSharp monitor not sense the closure of the channel made router-side. Is there a way to sense it? Thanks in advance.

darkl commented 7 years ago

What router? What client implementation (WebSocket4Net/System.Net.WebSockets)?

andeb91 commented 7 years ago

The router is Python-based. I'm developing a multiplatform application so the router is on Ubuntu with Python and the client on Android is based on jawampa.

darkl commented 7 years ago

The router is crossbario? Can you attach a simple C# code that connects to the router and fails to detect disconnections?

andeb91 commented 7 years ago

Yes, the router is crossbar.io implemented with autobahn-python. The code that I use to connect is this:

` WampChannelFactory factory = new WampChannelFactory(); channel = factory.ConnectToRealm("MyRealm") .WebSocketTransport("wss://10.0.0.101:8443/ws") .SetSecurityOptions(options => { options.EnabledSslProtocols = System.Security.Authentication.SslProtocols.Tls12; }) .JsonSerialization() .Build();

        channel.RealmProxy.Monitor.ConnectionBroken += OnConnectionBroken;
        channel.RealmProxy.Monitor.ConnectionError += OnConnectionError;
        channel.RealmProxy.Monitor.ConnectionEstablished += OnConnectionEstablished;

        Status.realmProxy = Status.channel.RealmProxy;

        Func<Task> connect = async () =>
        {
            await Status.channel.Open().ContinueWith(AfterChannelOpened).ConfigureAwait(false);
        };

        reconnector = new WampChannelReconnector(channel, connect);
        reconnector.Start();`
darkl commented 7 years ago

You are using the WebSocket4Net implementation. It automatically sends ping messages every 60 seconds by default. See here.

This mean that 60 seconds after the router gets down, WampSharp should detect this.

Elad

andeb91 commented 7 years ago

Oh, I see. Thank you. If I need less delay? For implementation reason I need to immediately react to the channel closure router-side. Jawampa give me the feedback immediately, is it possible to reach this also with WampSharp?

darkl commented 7 years ago

This will cost you by pinging the router every smaller interval. This can be achieved by providing you own WebSocket4NetFactory delegate to the first call.

factory.ConnectToRealm("MyRealm")
.WebSocketTransport(subprotocolName => new WebSocket("wss://10.0.0.101:8443/ws",subprotocolName)
{
    AutoSendPingInterval = 30
})
.SetSecurityOptions(options =>
{
    options.EnabledSslProtocols = System.Security.Authentication.SslProtocols.Tls12;
})
.JsonSerialization()
.Build();
andeb91 commented 7 years ago

I've tryed this solution but it doesn't work. It still not sensing the channel closure router-side.

darkl commented 7 years ago

Have you tried changing the AutoSendPingInterval value?

andeb91 commented 7 years ago

Yes, I also set AutoSendPingInterval to 1, but it doesn't work. I don't know why..

BTW, instead sensing the channel closure, can I sense the session killing router-side having also the killing reason? In other words can I have feedback on WampSharp client when the Autobahn-python router call all(u'wamp.session.kill', session, u'myreason', u'newuser')?

darkl commented 7 years ago

AutobahnPython is not a router, it is a client library. Your router is crossbario. You could probably get those details in the ConnectionBroken event handler. There are some similar properties of this event handler event args.

Elad

andeb91 commented 7 years ago

Ok, but there is however the problem that ConnectionBroken event is not raised. When on crossbar.io router I call wamp.session.kill, jawampa sense the session killing but WampSharp doesn't do that. But now I immagine that never exists a solution for this problem, isn't it?

darkl commented 7 years ago

This should be solved with version 1.2.6.44-beta (released moments ago).

Elad

andeb91 commented 7 years ago

Thanks a lot for this immediate fix; I very appreciate it! I've already tested the new release and now it seems it works like expected!

Andrea