41 lines
587 B
Go
41 lines
587 B
Go
package rtmp
|
|
|
|
import (
|
|
"net"
|
|
)
|
|
|
|
func NewServer(port *string) (error) {
|
|
l, err := net.Listen("tcp", ":" + *port)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
go start(l)
|
|
return nil
|
|
}
|
|
|
|
func start(l net.Listener) {
|
|
stream_live := false
|
|
for {
|
|
conn, err := l.Accept()
|
|
if err != nil {
|
|
continue
|
|
} else if stream_live {
|
|
conn.Close()
|
|
continue
|
|
}
|
|
stream_live = true
|
|
go handle_conn(conn, &stream_live)
|
|
}
|
|
}
|
|
|
|
func handle_conn(conn net.Conn, stream_live *bool) {
|
|
defer conn.Close()
|
|
if !DoHandshake(conn) {
|
|
return
|
|
}
|
|
if !NegoiateConnect(conn) {
|
|
return
|
|
}
|
|
|
|
*stream_live = false
|
|
}
|