简体   繁体   中英

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. 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/

I want to subscribe to the ticker channel and log the data in console.

I have istalled socket.io in order to accomplish this, and here is the code I have so far:

 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

How can I get live data from this websocket API?

You have a space in the URL: 'wss://api.poloniex.com '

net::ERR_NAME_NOT_RESOLVED indicates that the host name couldn't be 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! 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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