From 72948ff24c996e6cfcb60c8986b2fab13cae82a1 Mon Sep 17 00:00:00 2001 From: Muaz Ahmad Date: Mon, 21 Aug 2023 12:19:31 +0500 Subject: [PATCH] basic http server setup --- http/server.go | 34 ++++++++++++++++++++++++++++++++++ main.go | 15 +++++++++++++-- 2 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 http/server.go diff --git a/http/server.go b/http/server.go new file mode 100644 index 0000000..516426f --- /dev/null +++ b/http/server.go @@ -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) +} diff --git a/main.go b/main.go index b6f1490..a1620f2 100644 --- a/main.go +++ b/main.go @@ -1,6 +1,9 @@ package main -import "stream_server/rtmp" +import ( + "stream_server/rtmp" + "stream_server/http" +) const ( SRVTYPE_RTMP uint8 = iota @@ -11,7 +14,10 @@ func main() { if err != nil { panic(err) } - + err = NewHTTPServer("7879") + if err != nil { + panic(err) + } for { } } @@ -24,3 +30,8 @@ func NewIngestServer(srvr_type uint8, port string) (error) { } return err } + +func NewHTTPServer(port string) (error) { + err := http.NewServer(port) + return err +}