TCP echo rot13

This commit is contained in:
Meutel 2017-07-09 17:29:52 +02:00
parent 832053aa2c
commit d9437be5a2
2 changed files with 34 additions and 0 deletions

1
.gitignore vendored
View File

@ -48,3 +48,4 @@ tcpclient/tcpclient
tcpserver/tcpserver
echoserver/echoserver
example-redis/example-redis
echorot13/echorot13

33
echorot13/main.go Normal file
View File

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