dissertation-2-code/tcp/listener.go
Jake Hillion d65e8d3571
Some checks failed
continuous-integration/drone/push Build is failing
udp testing
2020-11-26 22:10:37 +00:00

43 lines
628 B
Go

package tcp
import (
"log"
"mpbl3p/proxy"
"net"
)
func NewListener(p *proxy.Proxy, local string, v proxy.MacVerifier) error {
laddr, err := net.ResolveTCPAddr("tcp", local)
if err != nil {
return err
}
listener, err := net.ListenTCP("tcp", laddr)
if err != nil {
return err
}
go func() {
for {
conn, err := listener.AcceptTCP()
if err != nil {
panic(err)
}
err = conn.SetWriteBuffer(0)
if err != nil {
panic(err)
}
f := Flow{conn: conn, isAlive: true}
log.Printf("received new tcp connection: %v\n", f)
p.AddConsumer(&f)
p.AddProducer(&f, v)
}
}()
return nil
}