Closed YohskDista closed 7 years ago
Some code for reproducing this would be helpful.
Elad
Here is the code for the program "B" who connects to the program "A"
Creation of the channel
try
{
// Create channel
Channel = new DefaultWampChannelFactory().CreateJsonChannel(SERVER_ADDRESS, REALM_NAME);
Channel.RealmProxy.Monitor.ConnectionError += Monitor_ConnectionError;
Channel.RealmProxy.Monitor.ConnectionBroken += Monitor_ConnectionBroken;
Channel.RealmProxy.Monitor.ConnectionEstablished += Monitor_ConnectionEstablished;
// Try connection
Channel.Open().Wait(5000);
// Connection OK => Get proxy / Create service
Service = Channel.RealmProxy?.Services?.GetCalleeProxy<IWampMediator>();
this.Subscribes = new List<IDisposable>()
{
Channel.RealmProxy.Services
.GetSubject<Data>(path1)
.Subscribe(data =>
{
lock (this.ServiceLock)
{
if (this.IsServiceReady)
this.ChangeDataEvent1?.Invoke(this, new DataEventArgs1(data));
}
}, OnSubscribeError),
Channel.RealmProxy.Services
.GetSubject<Data>(path2)
.Subscribe(data =>
{
lock (this.ServiceLock)
{
if (this.IsServiceReady)
this.ChangeDataEvent2?.Invoke(this, new DataEventArgs2(data));
}
}, OnSubscribeError)
};
}
catch (Exception e)
{
System.Diagnostics.Trace.TraceError("The connection could not be etablished : " + e.StackTrace);
}
Event of connection :
private void Monitor_ConnectionBroken(object sender, WampSharp.V2.Realm.WampSessionCloseEventArgs e)
{
DisposeConnection();
}
private void Monitor_ConnectionError(object sender, WampSharp.Core.Listener.WampConnectionErrorEventArgs e)
{
System.Diagnostics.Trace.TraceError("The connection has an error");
}
Dispose the connection when it is broken :
public void DisposeConnection()
{
lock(this.ServiceLock)
{
try
{
if (this.Subscribes?.Count > 0)
this.Subscribes.ForEach(T => T.Dispose());
if (Channel != null)
{
Channel.RealmProxy.Monitor.ConnectionError -= Monitor_ConnectionError;
Channel.RealmProxy.Monitor.ConnectionBroken -= Monitor_ConnectionBroken;
Channel.RealmProxy.Monitor.ConnectionEstablished -= Monitor_ConnectionEstablished;
Channel.Close("Disconnect", new GoodbyeDetails());
Channel = null;
}
Service = null;
System.Diagnostics.Trace.TraceError("********* Disposed ********");
}
catch (NullReferenceException)
{
System.Diagnostics.Trace.TraceError("Dispose() => is closed");
}
catch (WampConnectionBrokenException)
{
System.Diagnostics.Trace.TraceError("Dispose() => The connection is broked");
}
}
}
Thank you Leo
Are you using Framework 4.0?
Yes I do, excuse me I forgot to communicate this thing
I just published a new version to NuGet in which this issue should be resolved. Can you please check it? Elad
I have tested this morning and it seems to be ok, I haven't the exception anymore. I continue the tests and I let you know if I find something else.
Thank you for your quick response ! Leo
Hi again,
I had a strange problem on some machine. I have a local connection WampSharp on my PC between two software (I will call it A and B). The software "A" is a router who create the DefaultWampHost and register himself as a callee :
this is the code when it's close :
Now the "B" application connect to this WampHost and subscribe to different topic. The problem is when I close the WampHost the software "B" must be exit too. Then, I got an error before the closing of the software "B" :
When i got the connection broken I make different actions in this order :
Do you have some idea what could it be ?
Thank you Leo