2020-09-27 09:14:22 +00:00
|
|
|
package srt
|
|
|
|
|
|
|
|
import (
|
2020-09-27 18:43:00 +00:00
|
|
|
"fmt"
|
2020-09-27 09:14:22 +00:00
|
|
|
"log"
|
|
|
|
|
2020-09-27 18:43:00 +00:00
|
|
|
"github.com/haivision/srtgo"
|
2020-09-27 09:14:22 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Options holds web package configuration
|
|
|
|
type Options struct {
|
|
|
|
ListenAddress string
|
|
|
|
}
|
|
|
|
|
|
|
|
// Serve SRT server
|
|
|
|
func Serve(cfg *Options) {
|
|
|
|
log.Printf("SRT server listening on %s", cfg.ListenAddress)
|
|
|
|
|
2020-09-27 18:43:00 +00:00
|
|
|
options := make(map[string]string)
|
|
|
|
options["transtype"] = "file"
|
|
|
|
|
|
|
|
// FIXME: cfg.ListenAddress -> host and port
|
|
|
|
sck := srtgo.NewSrtSocket("0.0.0.0", 9710, options)
|
|
|
|
sck.Listen(1)
|
|
|
|
s, _ := sck.Accept()
|
2020-09-27 09:14:22 +00:00
|
|
|
|
2020-09-27 18:43:00 +00:00
|
|
|
buff := make([]byte, 2048)
|
|
|
|
for {
|
|
|
|
n, _ := s.Read(buff, 10000)
|
|
|
|
if n == 0 {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
fmt.Println("Received %d bytes", n)
|
2020-09-27 09:14:22 +00:00
|
|
|
}
|
|
|
|
}
|