I'm currently trying out the WampSharp implementation of the WAMP protocol.
I wanted the code to print a message on the consol when a client connects to it. So I created a router and a client. But the message doesn't appear in the console. Here's my code:
Router
class Program
{
static void Main(string[] args)
{
const string location = "ws://127.0.0.1:8080/";
const string realmName = "realm1";
Task runTask = Run(location, realmName);
Console.ReadLine();
}
private async static Task Run(string wsuri, string realmName)
{
using (IWampHost host = new DefaultWampHost(wsuri))
{
IWampHostedRealm realm = host.RealmContainer.GetRealmByName(realmName);
host.Open();
DefaultWampChannelFactory factory = new DefaultWampChannelFactory();
IWampChannel channel = factory.CreateJsonChannel(wsuri, realmName);
IWampClientConnectionMonitor monitor = channel.RealmProxy.Monitor;
monitor.ConnectionError += ConnectionError;
monitor.ConnectionEstablished += ConnectionEstablished;
Console.WriteLine("Server is running on " + wsuri);
while(true)
{
await Task.Delay(TimeSpan.FromSeconds(1))
.ConfigureAwait(false);
}
}
}
private static void ConnectionEstablished(object sender, WampSessionEventArgs e)
{
Console.WriteLine("A client as connected");
}
private static void ConnectionError(object sender, WampConnectionErrorEventArgs e)
{
Console.WriteLine("A connections error occured");
}
}
client:
class Program
{
static void Main(string[] args)
{
const string location = "ws://127.0.0.1:8080/";
DefaultWampChannelFactory channelFactory = new DefaultWampChannelFactory();
IWampChannel channel = channelFactory.CreateJsonChannel(location, "realm1");
IWampRealmProxy realmProxy = channel.RealmProxy;
channel.Open().Wait();
Console.ReadLine();
}
}
It's probably a C# problem rather than a WampSharp problem, but just in case I put the two wamp tags on this question.
You don't need to create a WampChannel in the router-side. You should subscribe to realm events instead:
If you're interested in detecting connection/disconnection of channel in client side, you can subscribe to the events you mentioned: