为什么使用websocketReuters在R中显示错误消息?

问题描述

我使用的代码与此示例中的https://github.com/Refinitiv/websocket-api/blob/master/Applications/Examples/R/market_price.R 但是,在此行中出现以下错误,有人可以修复吗?

> # Start websocket handshake
> ws_address = paste("ws://",hostname,":",port,"/",sep="")
> cat(paste("Connecting to WebSocket",ws_address,"...\n"))
Connecting to WebSocket ws://127.0.0.1:15000/ ...
> con = websocket(ws_address,port=as.integer(port),subprotocol="tr_json2",version=13)
Error in websocket(ws_address,port = as.integer(port),subprotocol = "tr_json2",: 
  Connection error

尝试以下代码并运行同一行后,错误已更改

> library(httpuv)

Attaching package: ‘httpuv’

The following object is masked from ‘package:websockets’:

    service

> library(websocket)

Attaching package: ‘websocket’

The following object is masked from ‘package:httpuv’:

    WebSocket

> s <- startServer("127.0.0.1",15000,+                  list(
+                    onWSOpen = function(ws) {
+                      # The ws object is a WebSocket object
+                      cat("Server connection opened.\n")
+                      
+                      ws$onMessage(function(binary,message) {
+                        cat("Server received message:",message,"\n")
+                        ws$send(message)
+                      })
+                      ws$onClose(function() {
+                        cat("Server connection closed.\n")
+                      })
+                    }
+                  )
+ )
> 
> ws <- websocket::WebSocket$new("ws://127.0.0.1:15000/")
> ws$onMessage(function(event) {
+   cat("Client received message:",event$data,"\n")
+ })
> 
> # Wait for a moment before running next line
> ws$send("hello world")
Error in wsSend(private$wsObj,msg) : invalid state
Server connection opened.
> con = websocket(ws_address,: 
  Connection timeout

或者,可能有不同的方法来获得与websocket(ws_address,version=13)命令相同的结果

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)