2019-12-28 21:07:03 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
"net"
|
|
|
|
)
|
|
|
|
|
2020-01-20 14:22:01 +00:00
|
|
|
type serverTcpListener struct {
|
2019-12-28 21:07:03 +00:00
|
|
|
p *program
|
|
|
|
netl *net.TCPListener
|
|
|
|
}
|
|
|
|
|
2020-01-20 14:22:01 +00:00
|
|
|
func newServerTcpListener(p *program) (*serverTcpListener, error) {
|
2019-12-28 21:07:03 +00:00
|
|
|
netl, err := net.ListenTCP("tcp", &net.TCPAddr{
|
|
|
|
Port: p.rtspPort,
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2020-01-20 14:22:01 +00:00
|
|
|
s := &serverTcpListener{
|
2019-12-28 21:07:03 +00:00
|
|
|
p: p,
|
|
|
|
netl: netl,
|
|
|
|
}
|
|
|
|
|
|
|
|
s.log("opened on :%d", p.rtspPort)
|
|
|
|
return s, nil
|
|
|
|
}
|
|
|
|
|
2020-01-20 14:22:01 +00:00
|
|
|
func (l *serverTcpListener) log(format string, args ...interface{}) {
|
|
|
|
log.Printf("[TCP listener] "+format, args...)
|
2019-12-28 21:07:03 +00:00
|
|
|
}
|
|
|
|
|
2020-01-20 14:22:01 +00:00
|
|
|
func (l *serverTcpListener) run() {
|
2019-12-28 21:07:03 +00:00
|
|
|
for {
|
2019-12-28 23:44:26 +00:00
|
|
|
nconn, err := l.netl.AcceptTCP()
|
2019-12-28 21:07:03 +00:00
|
|
|
if err != nil {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
2019-12-31 13:55:46 +00:00
|
|
|
rsc := newClient(l.p, nconn)
|
2019-12-29 00:52:52 +00:00
|
|
|
go rsc.run()
|
2019-12-28 21:07:03 +00:00
|
|
|
}
|
|
|
|
}
|