我试图连接到Poloniex。要连接,我使用WynthShop和此代码:
public class Program
{
public static void Main(string[] args)
{
var channelFactory = new DefaultWampChannelFactory();
var channel = channelFactory.CreateJsonChannel("wss://api.poloniex.com", "realm1");
channel.Open().GetAwaiter().GetResult();
var tickerSubject = channel.RealmProxy.Services.GetSubject("ticker");
var cancellationTokenSource = new CancellationTokenSource();
using (var subscr = tickerSubject.Subscribe(evt =>
{
var currencyPair = evt.Arguments[0].Deserialize<string>();
var last = evt.Arguments[1].Deserialize<decimal>();
Console.WriteLine($"Currencypair: {currencyPair}, Last: {last}");
}))
{
Console.WriteLine("Press a key to exit");
Console.ReadKey();
cancellationTokenSource.Cancel();
}
}
}
但不幸的是我收到错误&#34;无法连接到远程服务器&#34;。 也许有人知道如何解决连接问题。此外,我尝试使用以下代码,但也无法连接:
public class Program
{
static void Main(string[] args)
{
var channelFactory = new DefaultWampChannelFactory();
var channel = channelFactory.CreateJsonChannel("wss://api.poloniex.com", "realm1");
Func<Task> connect = async () =>
{
//await Task.Delay(30000);
await channel.Open();
var tickerSubject = channel.RealmProxy.Services.GetSubject("ticker");
var subscription = tickerSubject.Subscribe(evt =>
{
var currencyPair = evt.Arguments[0].Deserialize<string>();
var last = evt.Arguments[1].Deserialize<decimal>();
Console.WriteLine($"Currencypair: {currencyPair}, Last: {last}");
},
ex => {
Console.WriteLine($"Oh no! {ex}");
});
};
WampChannelReconnector reconnector =
new WampChannelReconnector(channel, connect);
reconnector.Start();
Console.WriteLine("Press a key to exit");
Console.ReadKey();
}
}
答案 0 :(得分:0)
我自己创建了websocket,指定了我可以支持的SSL / TLS版本
public void Connect()
{
_channel = new DefaultWampChannelFactory().ConnectToRealm(_realm)
.WebSocketTransport(prtcl => CreateWebSocket(prtcl, _url))
.JsonSerialization()
.Build();
//.CreateJsonChannel(_url, _realm);
//_channel.RealmProxy.
_channel.RealmProxy.Monitor.ConnectionBroken += (sender, args) =>
{
_logger.WriteError(string.Format("ConnectionError -> From connection error event WssUrl : {0} , Realm : {1}", _url, _realm), new ArgumentException(args.Details != null ? args.Details.Message : "NO Details" ));
};
_channel.RealmProxy.Monitor.ConnectionError += (sender, args) =>
{
_logger.WriteError(string.Format("ConnectionError -> From connection error event WssUrl : {0} , Realm : {1}",_url,_realm), args.Exception);
};
_channel.RealmProxy.Monitor.ConnectionEstablished += (sender, args) =>
{
string info = string.Format("from ConnectionEstablished event -> WssUrl : {0} , Realm : {1}", _url, _realm);
OnConnected(info);
};
_reconnector = new WampChannelReconnector(_channel, ConnectInternal);
_reconnector.Start();
}
private static WebSocket CreateWebSocket(string subprotocolName, string serverAddress)
{
WebSocket result = new WebSocket(serverAddress,
subprotocolName, null, null, string.Empty, string.Empty, WebSocketVersion.None,null,SslProtocols.Ssl3 | SslProtocols.Tls | SslProtocols.Tls11 | SslProtocols.Tls12, 4096);
result.AutoSendPingInterval = 10;
return result;
}
答案 1 :(得分:-1)