stream-server/http/server.go

34 lines
461 B
Go

package http
import (
"net"
"fmt"
)
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) {
for {
conn, err := l.Accept()
if err != nil {
continue
}
go handle_conn(conn)
}
}
func handle_conn(conn net.Conn) {
defer conn.Close()
buf := make([]byte, 1024)
if _, err := conn.Read(buf); err != nil {
return
}
fmt.Println(buf)
}