WampSharp无法连接到Poloniex?

时间:2016-07-23 00:57:11

标签: c# wamp wampsharp

以下是使用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();

虽然不起作用,但订阅中的代码永远不会运行。也用CreateJsonChannel尝试了它,但它也不起作用。

任何想法可能出错?

1 个答案:

答案 0 :(得分:1)

您的代码运行正常。只需摆脱Console.ReadLine - 它会阻止WebSocket线程,因此WampSharp无法获取任何进一步的消息。 您可以将一个Console.ReadLine添加到Main。

另见blog post