33 lines
401 B
Go
33 lines
401 B
Go
|
package conn
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"net"
|
||
|
)
|
||
|
|
||
|
const (
|
||
|
Port = ":3030"
|
||
|
Type = "tcp4"
|
||
|
)
|
||
|
|
||
|
func StartSimple(handler func(conn net.Conn)) error {
|
||
|
l, err := net.Listen(Type, Port)
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
defer l.Close()
|
||
|
|
||
|
fmt.Println(fmt.Sprintf("Listening on port %s", Port))
|
||
|
|
||
|
for {
|
||
|
c, err := l.Accept()
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
go handler(c)
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
}
|
||
|
}
|