basic http server setup

This commit is contained in:
Muaz Ahmad 2023-08-21 12:19:31 +05:00
parent 5941184ada
commit 72948ff24c
2 changed files with 47 additions and 2 deletions

34
http/server.go Normal file
View file

@ -0,0 +1,34 @@
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)
}

15
main.go
View file

@ -1,6 +1,9 @@
package main package main
import "stream_server/rtmp" import (
"stream_server/rtmp"
"stream_server/http"
)
const ( const (
SRVTYPE_RTMP uint8 = iota SRVTYPE_RTMP uint8 = iota
@ -11,7 +14,10 @@ func main() {
if err != nil { if err != nil {
panic(err) panic(err)
} }
err = NewHTTPServer("7879")
if err != nil {
panic(err)
}
for { for {
} }
} }
@ -24,3 +30,8 @@ func NewIngestServer(srvr_type uint8, port string) (error) {
} }
return err return err
} }
func NewHTTPServer(port string) (error) {
err := http.NewServer(port)
return err
}