stream-server/http/server.go

35 lines
461 B
Go
Raw Normal View History

2023-08-21 12:19:31 +05:00
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)
}