doumizhi0809 2017-01-16 17:49
浏览 64
已采纳

Golang在我的视频流上超时

I am trying to write a go server that receives a stream of data from an http request. The problem is that it times out once it receives {status: connected} How do I keep the connection alive?

func stream() {
    t := time.Now()
    a := t.Format("15:03")
    if a > string("08:30") && a < string("15:00") {
        color.Red("Streaming. . .")
        config := oauth1.NewConfig("HIDDEN", "HIDDEN")
        token := oauth1.NewToken("HIDDEN", "HIDDEN")
        httpClient := config.Client(oauth1.NoContext, token)
        path := "https://stream.tradeking.com/v1/market/quotes.json?symbols=aapl"
        resp, _ := httpClient.Get(path)
        fmt.Println(resp)
        body, _ := ioutil.ReadAll(resp.Body)
        fmt.Printf("Raw Response Body:
%v
", string(body))
        defer resp.Body.Close()
    } else {
        color.Red("%s 
Markets are closed! Please, come back later.", t)
    }
}

I call this function in main. I also receive what looks like the header: &{200 OK 200 HTTP/1.1 1 1 map[Date:[Mon, 16 Jan 2017 17:45:36 GMT] X-Powered-By:[Express] Server:[cloudflare-ngi nx] Content-Type:[application/json] Connection:[keep-alive] Set-Cookie:[__cfduid=dcfcf86c79c56e659ce2b1bade3643c 981484588736; expires=Tue, 16-Jan-18 17:45:36 GMT; path=/; domain=.tradeking.com; HttpOnly] Vary:[Accept-Encodin g] Cf-Ray:[322361d0efd40938-DFW]] 0xc42032e0c0 -1 [chunked] false true map[] 0xc4200d21e0 0xc42040cbb0}

  • 写回答

1条回答 默认 最新

  • dsasd12314 2017-01-17 06:27
    关注

    Turn out that the the market was closed for MLK Day and hence there was no response from the sever.

    After a certain timeout, the remote server times out.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#python#的问题:求帮写python代码
  • ¥15 LiBeAs的带隙等于0.997eV,计算阴离子的N和P
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 来真人,不要ai!matlab有关常微分方程的问题求解决,
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?