老师我的代码和你是一样的,
func (m middleWareHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { if !m.l.GetConn() { sendErrorResponse(w, http.StatusTooManyRequests, "Too many requests.") return } m.r.ServeHTTP(w, r) defer m.l.ReleaseConn() }
func streamHandler(w http.ResponseWriter, r *http.Request, p httprouter.Params) { vid:=p.ByName("vid-id") vl:=VIDEO_DIR+vid video, err:=os.Open(vl) if err!=nil{ sendErrorResponse(w, http.StatusInternalServerError, "error of open video: " + err.Error()) return } w.Header().Set("Content-Type", "video/mp4") http.ServeContent(w, r, "", time.Now(), video) defer video.Close() }
不知道为什么我的视频刚开始播放时控制台就开始打印,如下所示:
2018/06/25 22:44:07 Successfully got connection
2018/06/25 22:44:08 New connection coming: 1
2018/06/25 22:44:08 Successfully got connection
2018/06/25 22:44:08 New connection coming: 1
2018/06/25 22:44:08 Successfully got connection
2018/06/25 22:44:08 New connection coming: 1
2018/06/25 22:44:08 Successfully got connection
2018/06/25 22:44:16 New connection coming: 1
于是我的limiter control当然失败了,设了buffer容量缓冲为2没有用,现在我感觉我的代码和老师一样但就是可以开N个窗口同时播放。。。。
老师可以的话能pull一下我的代码检查一下吗。。。
https://github.com/sd1700092/video_server.git
应该不会花您很长时间的,谢谢了。。。