2016-07-23 97 views
8

这是我使用WampSharp的最新预发布版本非常简单的代码:WampSharp无法连接到Poloniex?

 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也是如此,那也行不通。

任何想法可能是错误的?

+0

我正在尝试使用poloniex websocket api。你有没有工作示例代码? – Luther

+0

你解决了吗? –

+0

这是他们的API,而不是你的代码。他们的API不发送数据。我试着用发布的node.js例子,也没有数据返回。 – Simoyd

回答

1

您的代码正常工作。只要摆脱Console.ReadLine - 它阻止WebSocket线程,因此WampSharp无法获得任何进一步的消息。 您可以将Console.ReadLine添加到Main中。请参阅blog post

+0

这是没有意义的,因为他们的示例显示了这一点:http://wampsharp.net/wamp2/roles/subscriber/getting-started-with-subscriber/ – YesMan85

+1

区别在于,在您链接到的示例中,它们使用'''channel.Open.Wait(5000)'''而不是'''等待channel.Open()'''。 await关键字导致下一行在WebSocket的线程上运行。 – darkl

+0

啊我看到了,我纠正了。 – YesMan85