stream-server/rtmp/server.go

51 lines
862 B
Go
Raw Normal View History

2023-08-09 16:00:21 +05:00
package rtmp
import (
"net"
)
2023-08-10 15:29:10 +05:00
type ProtocolParams struct {
peer_chunk_size uint32
chunk_size uint32
peer_ack_win uint32
curr_read uint32
}
2023-08-09 16:00:21 +05:00
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
}
2023-08-10 15:29:10 +05:00
params := ProtocolParams{1024, 512, 0, 0}
open_chnkstrms, open_msgs, chunk_buffers := OpenStreamsMapInit()
if !NegotiateConnect(conn, &params, open_chnkstrms, open_msgs, chunk_buffers) {
2023-08-09 16:00:21 +05:00
return
}
*stream_live = false
}