doubi4435
2016-10-31 03:04
浏览 388
已采纳

Go-Web服务器在同一端口上侦听多个协议(HTTP和RTMP)

I'm trying to implement the RTMP protocol to along side my web application in Go, however I can't seem to figure out solution to handle both HTTP and and RTMP on the same port.

The idea would be something such as this.

package main

import (
    "fmt"
    "io"
    "net/http"
)

func main() {
    http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
        io.WriteString(w, "Hello!")
    })

    http.HandleFunc("/rtmp", func(w http.ResponseWriter, r *http.Request) {
        // RTMP handling here
    })

    fmt.Println("Starting web server")
    http.ListenAndServe(":8000", nil)
}

zhangpeihao/gortmp has a great RMTP module with an example that shows handling RTMP by listening on a TCP socket. However how can handle it on a specific endpoint rather then a second port?

图片转代码服务由CSDN问答提供 功能建议

我正在尝试在Go中与我的Web应用程序一起实现RTMP协议,但是我似乎无法 找出可以在同一端口上同时处理HTTP和RTMP的解决方案。

想法可能是这样的。

  包main 
 
import(
“ fmt” 
“ io” 
“ net / http” 
)
 
func main(){
 http.HandleFunc(“ /”,func(w http。  ResponseWriter,r * http.Request){
 io.WriteString(w,“ Hello!”)
})
 
 http.HandleFunc(“ / rtmp”,func(w http.ResponseWriter,r * http。 请求){
 // RTMP处理在这里
})
 
 fmt.Println(“启动Web服务器”)
 http.ListenAndServe(“:8000”,nil)
} 
    
 
 

zhangpeihao / gortmp 具有一个很棒的RMTP模块,其中显示通过侦听RTMP处理RTMP的示例 TCP 插座。 但是,如何在特定端点而不是第二个端口上处理它?<​​/ p>

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

相关推荐 更多相似问题