WampSharp无法连接到Poloniex?

Ara*_*ami 8 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();
Run Code Online (Sandbox Code Playgroud)

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

什么想法可能是错的?

dar*_*rkl 1

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

另请参阅博客文章

  • 不同之处在于,在您链接到的示例中,它们使用 ```channel.Open.Wait(5000)``` 而不是 ```await channel.Open()```。wait 关键字导致下一行在 WebSocket 的线程上运行。 (2认同)