【发布时间】:2021-04-18 19:10:11
【问题描述】:
我在尝试连接 websocket 服务器时遇到问题。
我需要订阅以获取欧元/美元的当前价格,但我不断收到此对象:{topic: "keepalive"}。
它应该返回价格和最新的时间戳;
这是我的代码:
import { w3cwebsocket as W3CWebSocket } from "websocket";
export default function LogIn() {
const client = new W3CWebSocket('ws://stream.tradingeconomics.com/?client=guest:guest');
useEffect(()=>{
client.onopen = function(e) {
console.log("Connection established!");
client.send(JSON.stringify({topic: "subscribe", to: "EURUSD:CUR"}))
client.onmessage = function(e) { console.log(e); };
};
},[])
非常感谢您的帮助!
【问题讨论】: