TCP echo rot13
This commit is contained in:
parent
832053aa2c
commit
d9437be5a2
1
.gitignore
vendored
1
.gitignore
vendored
@ -48,3 +48,4 @@ tcpclient/tcpclient
|
||||
tcpserver/tcpserver
|
||||
echoserver/echoserver
|
||||
example-redis/example-redis
|
||||
echorot13/echorot13
|
||||
|
33
echorot13/main.go
Normal file
33
echorot13/main.go
Normal 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()
|
||||
}()
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user