我使用与此示例中相同的代码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, port=as.integer(port), subprotocol="tr_json2", version=13)
Error in websocket(ws_address, port = as.integer(port), subprotocol = "tr_json2", :
Connection timeout
或者,可能有不同的方法来获得与websocket(ws_address, port=as.integer(port), subprotocol="tr_json2", version=13)
命令相同的结果