35 lines
572 B
Go
35 lines
572 B
Go
|
package main
|
||
|
|
||
|
import (
|
||
|
"bufio"
|
||
|
"fmt"
|
||
|
"net"
|
||
|
"strings"
|
||
|
)
|
||
|
|
||
|
func main() {
|
||
|
ln, err := net.Listen("tcp", ":1302")
|
||
|
catchErr(err)
|
||
|
fmt.Println("Listening on port 1302")
|
||
|
|
||
|
conn, err := ln.Accept()
|
||
|
catchErr(err)
|
||
|
|
||
|
for {
|
||
|
message, err := bufio.NewReader(conn).ReadString('\n')
|
||
|
catchErr(err)
|
||
|
fmt.Printf("Message received: %v", string(message))
|
||
|
newMsg := strings.ToUpper(message)
|
||
|
conn.Write([]byte(newMsg + "\n"))
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func catchErr(err error) (errHappened bool) {
|
||
|
errHappened = false
|
||
|
if err != nil {
|
||
|
errHappened = true
|
||
|
fmt.Println(err)
|
||
|
}
|
||
|
return errHappened
|
||
|
}
|