我一直在使用WampSharp,也就是为连接autobahn wamp websocket而提供的客户端库。
我已经使用以下代码(使用.Net客户端应用程序)成功地连接了我在python中创建的Autobahn (使用WampSharp):
DefaultWampChannelFactory channelFactory = new DefaultWampChannelFactory();
channel = channelFactory.CreateChannel(serverAddress);
channel.Open();这里的serverAddress是: 127.0.0.1:8000 (即我的websocket从8000端口开始)。我的本地机器)。
我使用pubsub机制来交换由autobahn wamp websocket提供的数据,使用以下代码:
public void Subscribe()
{
ISubject<string> subscribe1 = channel.GetSubject<string>(@"simple/topicSubject1");
IDisposable subject1 = subscribe1.Subscribe(msg => MessageRecieved(msg));
}
public void Publish()
{
ISubject<string> subjectForPublish = channel.GetSubject<string>(@"simple/topicSubject1");
subjectForPublish.OnNext(sd.SerializeObject(DataToPublish));
}所有这些过程都成功地完成了。我面临的问题是,我找不到任何处理程序来处理错误和连接丢失,就像我们在传统的websocket中所做的那样。在传统的websocket中,我们有如下处理程序:
webSocket.Error += new EventHandler<SuperSocket.ClientEngine.ErrorEventArgs>(webSocket_Error);
webSocket.Closed += new EventHandler(webSocket_Closed); 我需要实现上述功能使用万普夏普。
提前谢谢。
发布于 2014-07-23 21:44:40
试试这个:
DefaultWampChannelFactory factory = new DefaultWampChannelFactory();
IWampChannel<JToken> channel = factory.CreateChannel("ws://localhost:9090/ws");
IWampClientConnectionMonitor monitor = channel.GetMonitor();
monitor.ConnectionError += ConnectionError;
monitor.ConnectionEstablished += ConnectionEstablished;
monitor.ConnectionLost += ConnectionLost;
await channel.OpenAsync();https://stackoverflow.com/questions/24910800
复制相似问题