2016-07-23 4 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을 메인에 추가 할 수 있습니다.

도 참조하십시오. 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

관련 문제