0
제발,이 요지를 확인하고 뭐가 잘못 됐는지 말해줘?
왜 내 메시지가 보이지 않습니까?
요지 :Flush()가 작동하지 않음
func send(param martini.Params, r render.Render) {
Ct.Msgs <- param["msg"]
fmt.Printf("Sent: %v", param["msg"])
r.JSON(http.StatusOK, Response{"status": "ok"})
}
그리고 watch
기능 :
func watch(rw http.ResponseWriter, r render.Render) {
var msg string
ok := true
for ok {
select {
case msg, ok = <-Ct.Msgs:
rw.Write([]byte(msg))
fmt.Printf("Wrote: %v", msg)
f, ok := rw.(http.Flusher)
if ok {
f.Flush()
fmt.Println("Flushed")
} else {
r.JSON(http.StatusOK, Response{"status": "error", "descr": "CANT_FLUSH"})
return
}
}
}
r.JSON(http.StatusOK, Response{"status": "ok", "descr": "finished"})
}
가 작동하지 않는 이유는 https://gist.github.com/cnaize/895f61b762a9f5ee074c
간단한 경우에, 나는 두 가지 기능을 가지고?
편집 됨 :
내 요점 업데이트되었습니다. 지금 어디에 :
if i, err := rw.Write([]byte(msg)); err != nil {
r.JSON(http.StatusOK, Response{"status": "error", "descr": err.Error()})
return
} else {
fmt.Printf("i: %v", i)
}
그리고 로그에 있습니다
Sent: hello
i: 5
Wrote: hello
Flushed
그러나 나는 아무것도 볼 수 없습니다.
아이디어가 있으십니까?
@CharlieTumahai를가 "플러시"메시지를 출력,하지만 난 구글 크롬 버전 38.0을 사용하고 브라우저에서 – cnaize
@CharlieTumahai를 메시지가 표시되지 않습니다. 2125.101 (64 비트) – cnaize
http : // localhost : 3000/watch를 수행하여 @CharlieTumahai – cnaize