【问题标题】:socketio4net error initializing handshakesocketio4net 初始化握手时出错
【发布时间】:2014-02-06 10:07:07
【问题描述】:

我在 OSX 上使用 Xamarin(mono 3.2.5) 创建一个连接到 blockchain.info websocket 流的 C# 控制台应用程序。我已经包含了来自 NuGet 的 socketio4net 库,并认为我正确地遵循了规范,但我对 socket.io 连接一般来说有点新,所以请纠正我做错了什么。调用下面的 socket.Connect() 方法后,我立即收到错误。

我已经创建了一些这样的事件处理程序:

static void SocketOpened(object sender, EventArgs e) 
{
    Console.WriteLine ("opened event handler");
    Console.WriteLine (e.ToString());
}

static void SocketError(object sender, SocketIOClient.ErrorEventArgs e) 
{
    Console.WriteLine ("error event handler");
    Console.WriteLine (e.Message);
}

static void SocketMessage(object sender, MessageEventArgs e) 
{
    Console.WriteLine ("message event handler");
    Console.WriteLine (e.Message);
}

我的代码如下:

var socket = new Client (@"ws://ws.blockchain.info:8335/inv");
socket.Opened += SocketOpened;
socket.Error += SocketError;
socket.Message += SocketMessage;

socket.Connect ();
Console.WriteLine ("handshake: " + socket.HandShake.ErrorMessage);

socket.On("connect", (fn) => {
    Console.WriteLine("On.connect msg: " + fn.MessageText);
});

socket.On ("open", (fn) => {
    Console.WriteLine("On.open msg: " + fn.MessageText);
});

我的控制台输出:

error event handler
Error initializing handshake with ws://ws.blockchain.info:8335/inv
handshake: Error getting handsake from Socket.IO host instance: An error occurred performing a WebClient request.

我做错了什么?区块链 API 文档在这里:https://blockchain.info/api/api_websocket,我已经尝试了他们指定的两个 URL。在 URL 中省略端口号会产生不同的错误。它似乎不是“执行 WebClient 请求时出错”,而是寻找到套接字服务器的本地路径,这显然是不正确的。

非常感谢有经验的程序员提供任何帮助

【问题讨论】:

  • 我也有同样的问题,你解决了吗?
  • @GreenEyedAndy 你解决了吗?

标签: c# sockets mono bitcoin socketio4net


【解决方案1】:

我面临同样的问题,就我而言,这是因为办公室的默认互联网连接必须通过代理。

只需使用以下代码将代理设置为无,即可解决我的问题。

System.Net.WebRequest.DefaultWebProxy = null;

【讨论】:

    猜你喜欢
    • 2016-08-15
    • 2014-08-04
    • 1970-01-01
    • 2020-09-14
    • 1970-01-01
    • 2016-09-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多