websocket连接不起作用 [英] websocket connection does not work
问题描述
我似乎在与 R 中的 websockets 斗争.我想将比特币交易所 MtGox 的流数据直接下载到 R,但 R 无法建立连接.
I seem to be in struggle with the websockets in R. I wanted to download the streaming data from the BitCoin exchange MtGox directly to R, but R cannot establish the connection.
websocket 规范定义为:
The websocket specs are defined as:
- 主机:websocket.mtgox.com 或 socketio.mtgox.com
- 端口:80 或 443 ( ssl )
- 命名空间:/mtgox(包括开始斜线)
- Host: websocket.mtgox.com or socketio.mtgox.com
- Port: 80 or 443 ( ssl )
- Namespace: /mtgox (Including beginning slash)
网址了解更多详情:https://en.bitcoin.it/wiki/MtGox/API/流媒体
我的代码是:
require(websockets)
con = websocket("https://socketio.mtgox.com/mtgox",port=443)
我总是以错误告终:
> con = websocket("https://socketio.mtgox.com/mtgox",port=443)
Error in websocket("https://socketio.mtgox.com/mtgox", port = 443) :
Connection error
有人知道出了什么问题吗?
Does anyone have an idea what is wrong?
非常感谢.
推荐答案
我在这里查看了源代码和手册 - https://github.com/rstudio/R-Websockets
I've looked at the source code and manual here - https://github.com/rstudio/R-Websockets
R Websocket 库已经过时,不符合目前的 WebSocket 协议.
The R Websocket library is out of date and not compliant with the WebSocket protocol as it stands.
因此您需要修复图书馆或寻找替代图书馆.根据您的能力,修复库并不难.我在这里做到了 -
So you'd need to fix the library or find an alternate one. Fixing the library isn't that hard depending on your ability. I managed to do it here -
https://github.com/zeenogee/R-Websockets
我的(懒惰地)硬编码到 MtGox - 使用风险自负!您需要删除当前的 WebSocket 库并安装这个库.不要忘记你的代码只是做基本的连接.还需要几个步骤才能查看实际数据 -
My one is (lazily) hard-coded to MtGox - use at own risk! You'd need to remove the current WebSocket library and install this one. Don't forget Your code is only doing the basic connection. There are a couple more steps to see actual data -
set_callback("receive", function(DATA,WS,HEADER) cat(rawToChar(DATA)), con)
service (con)
这篇关于websocket连接不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!