标签: wampsharp

WampSharp无法连接到Poloniex?

这是使用WampSharp的最新预发布版本的非常简单的代码:

        var channelFactory = new DefaultWampChannelFactory();
        var channel = channelFactory.CreateMsgpackChannel("wss://api.poloniex.com", "realm1");
        await channel.Open();

        var realmProxy = channel.RealmProxy;

        Console.WriteLine("Connection established");

        int received = 0;
        IDisposable subscription = null;

        subscription =
            realmProxy.Services.GetSubject("ticker")
                      .Subscribe(x =>
            {
                Console.WriteLine("Got Event: " + x);

                received++;

                if (received > 5)
                {
                    Console.WriteLine("Closing ..");
                    subscription.Dispose();
                }
            });

        Console.ReadLine();
Run Code Online (Sandbox Code Playgroud)

但是不起作用,订阅中的代码永远不会运行.也尝试过CreateJsonChannel,这也不起作用.

什么想法可能是错的?

c# wamp wampsharp

8
推荐指数
1
解决办法
1787
查看次数

如何使用WampSharp处理错误和连接关闭

我一直在使用WampSharp,即提供的客户端库与autobahn wamp websocket连接.

我使用以下代码(使用WampSharp)使用.Net客户端应用程序成功连接到我在python中创建的Autobahn Wamp Websocket:

DefaultWampChannelFactory channelFactory = new DefaultWampChannelFactory();
channel = channelFactory.CreateChannel(serverAddress);
channel.Open();
Run Code Online (Sandbox Code Playgroud)

这里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));
}
Run Code Online (Sandbox Code Playgroud)

这些所有流程都已成功完成.我面临的问题是我找不到任何处理程序来处理错误和连接丢失,就像我们在传统的websocket中所做的那样.在传统的websocket中,我们有以下处理程序:

webSocket.Error += new EventHandler<SuperSocket.ClientEngine.ErrorEventArgs>(webSocket_Error);
webSocket.Closed += new EventHandler(webSocket_Closed); 
Run Code Online (Sandbox Code Playgroud)

我需要使用wampsharp来实现上述功能.

提前致谢.

c# publish-subscribe websocket autobahn wampsharp

4
推荐指数
1
解决办法
1206
查看次数

标签 统计

c# ×2

wampsharp ×2

autobahn ×1

publish-subscribe ×1

wamp ×1

websocket ×1