2016-07-23 96 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