basic tcp handling

main
Nick Dumas 1 year ago
parent 0ff68c5f5e
commit ce2cc4a3c6

@ -3,28 +3,30 @@ package main
import ( import (
"bufio" "bufio"
"fmt" "fmt"
"log"
"github.com/therealfakemoot/go-telnet" "net"
) )
type MUDHandler struct { 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() { func main() {
var handler telnet.Handler = MUDHandler{} l, err := net.Listen("tcp", ":5555")
if err != nil {
err := telnet.ListenAndServe(":5555", handler) log.Fatal(err)
if nil != err { }
//@TODO: Handle this error better. defer l.Close()
panic(err) 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)
} }
} }

Loading…
Cancel
Save