The resource loading... loading...

hbdm and ok contract simultaneously with websocket, huobi sends out pong without response

Author: guangtianxia, Created: 2019-03-21 00:35:45, Updated: 2019-03-21 11:26:42

The code is like this, huobi will receive the server's ping after about five or six seconds, and then I'll send out a pong, but it's like the server can't receive a pong, and it keeps sending me a ping, and God says to read plus 1, but plus or minus.

function main() {
    var ws_hbdm = Dial("wss://www.hbdm.com/ws?compress=true|compress=gzip&mode=recv")
    var ws_ok= Dial("wss://real.okex.com:10440/ws/v1?compress=true|compress=gzip_raw&mode=recv")
    var pingCyc = 1000 * 120
    var lastPingTime = new Date().getTime()
    if(ws_hbdm && ws_ok){
        ws_hbdm.write('{"sub": "market.EOS_CW.depth.step6","id": "id2"}')
        ws_ok.write("{'event':'addChannel','channel':'ok_sub_futureusd_eos_depth_this_week_5'}")
        while(1){
            //读取huobi数据
            var ret = ws_hbdm.read(-1)
            if(ret){
                var ret1=JSON.parse(ret)
                if("tick" in ret1){
                    Log("huobi",ret1.tick) 
                }else if("ping" in ret1){
                    ws_hbdm.write('{"pong":'+parseInt(ret1.ping)+'}')
                    Log("pong")
                }    
            }
            //读取ok数据
            var nowTime = new Date().getTime()
            var ret2 = ws_ok.read(-1)
            if(ret2){
                if(nowTime - lastPingTime > pingCyc){
                    ws_ok.write("{'event':'ping'}")
                    lastPingTime = nowTime
                }
                var ret3=JSON.parse(ret2)
                if(ret3.length>0){
                    if("data" in ret3[0]){
                        Log("ok",ret3[0].data)
                    }
                }
            }
        }
        //ws_hbdm.close() 
    }
}

The logs are as follows: 2019-03-21 00:30:25 info ok {asks:[[3.687,18]]. 2019-03-21 00:30:24 information ok {asks: [[3.687,1684]]. === The following is a list of articles related to the current president of the United States. === The current president of the United States. === The current president of the United States. === The current president of the United States. === The current president of the United States. === The current president of the United States. 2019-03-21 00:30:24 information pong and other news 2019-03-21 00:30:23 information ok {asks you: [[3.687,1684]]. 2019-03-21 00:30:23 information ok {asks you: [[3.687,1711,4640]].

The Coin APIhttps://github.com/huobiapi/API_Docs/wiki/WS_request


More

The grassSee if it's the server location, and update the host.

The grass/upload/asset/292ead2ae2ccd91659e.jpg Copy your code I tried it and it worked

The grassSome exchange servers send out a ping check link every few seconds.

The grassYou're too old, you're too old, you're too old, you're too old, you're too old.

guangtianxiaThank you! Updated the host, good.

guangtianxiaFor example, the code, I want to get the market data of OK and the token at the same time, OK can receive the market data all the time, but the token does not receive after 5 seconds (I also responded to a ping), so I wanted to get help to look at the code, to find out why, I found two days.

The grassI don't know what's wrong with you.

guangtianxiaYes, I received ping checks and immediately replied pong, xxx.read ((() this is okay to read and then return pong, xxx.read ((-1)) this is not okay, I don't know why