go-examples/echorot13/main.go

34 lines
439 B
Go
Raw Normal View History

2017-07-09 15:29:52 +00:00
package main
import (
"bufio"
"io"
"net"
"github.com/wayneashleyberry/rot13"
)
func main() {
ln, err := net.Listen("tcp", ":9000")
if err != nil {
panic(err)
}
defer ln.Close()
for {
conn, err := ln.Accept()
if err != nil {
panic(err)
}
go func() {
scanner := bufio.NewScanner(conn)
for scanner.Scan() {
str := scanner.Text()
io.WriteString(conn, rot13.Encode(str))
}
conn.Close()
}()
}
}