From ce2cc4a3c6ff34520c94e6e4950ff9b76baaf00e Mon Sep 17 00:00:00 2001 From: Nick Dumas Date: Fri, 18 Aug 2023 21:55:49 -0400 Subject: [PATCH] basic tcp handling --- cmd/echo.go | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/cmd/echo.go b/cmd/echo.go index d36399e..4950c99 100644 --- a/cmd/echo.go +++ b/cmd/echo.go @@ -3,28 +3,30 @@ package main import ( "bufio" "fmt" - - "github.com/therealfakemoot/go-telnet" + "log" + "net" ) type MUDHandler struct { } -func (mh MUDHandler) ServeTELNET(ctx telnet.Context, w telnet.Writer, r telnet.Reader) { - s := bufio.NewScanner(r) - // s.Split(bufio.ScanWords) - - for s.Scan() { - fmt.Printf("Received user input: %q\n", s.Text()) - } -} - func main() { - var handler telnet.Handler = MUDHandler{} - - err := telnet.ListenAndServe(":5555", handler) - if nil != err { - //@TODO: Handle this error better. - panic(err) + l, err := net.Listen("tcp", ":5555") + if err != nil { + log.Fatal(err) + } + defer l.Close() + for { + conn, err := l.Accept() + if err != nil { + log.Fatal(err) + } + go func(c net.Conn) { + s := bufio.NewScanner(c) + defer c.Close() + for s.Scan() { + fmt.Printf("Received user input: %q\n", s.Text()) + } + }(conn) } }