简体   繁体   English

连接到远程websocket angularjs

[英]Connect to remote websocket angularjs

I am trying to connect to a remote push API websocket (in the client / browser, not in the backend) and log the live data in the console. 我试图连接到远程推送API websocket(在客户端/浏览器中,而不在后端中),并将实时数据记录在控制台中。 I have been searching for a while and can't find any examples of this. 我已经搜索了一段时间,但找不到任何示例。

This is the API I'm trying to connect to: https://poloniex.com/support/api/ 这是我尝试连接的API: https : //poloniex.com/support/api/

I want to subscribe to the ticker channel and log the data in console. 我想subscribe ticker并在控制台中记录数据。

I have istalled socket.io in order to accomplish this, and here is the code I have so far: 我已经安装了socket.io来完成此操作,这是到目前为止的代码:

 var socket = io.connect('wss://api.poloniex.com '); io.on('connection', function(socket){ socket.join('ticker'); }); 

Chrome inspector is showing error, repeatedly every second or two: https://api.poloniex.com%20/socket.io/?EIO=3&transport=polling&t=LqCBLTn net::ERR_NAME_NOT_RESOLVED Chrome检查器每两秒钟重复显示错误: https://api.poloniex.com%20/socket.io/?EIO=3&transport=polling&t=LqCBLTn net::ERR_NAME_NOT_RESOLVED

How can I get live data from this websocket API? 如何从此websocket API获取实时数据?

You have a space in the URL: 'wss://api.poloniex.com ' URL中有一个空格: 'wss://api.poloniex.com '

net::ERR_NAME_NOT_RESOLVED indicates that the host name couldn't be resolved. net::ERR_NAME_NOT_RESOLVED表示无法解析主机名。 So you should look at the host name you're trying to reach. 因此,您应该查看要尝试访问的主机名。 api.poloniex.com%20 could not be resolved because you probably don't have a domain registered with a .com%20 TLD! api.poloniex.com%20无法解析,因为您可能没有向.com%20 TLD注册的域! Simply remove the space in the first line of your snippet and, assuming your DNS records are setup accordingly, you shouldn't get net::ERR_NAME_NOT_RESOLVED anymore. 只需删除代码片段第一行中的空格,并假设已相应设置DNS记录, net::ERR_NAME_NOT_RESOLVED不再应该使用net::ERR_NAME_NOT_RESOLVED

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM