Added ability to use custom ports
This commit is contained in:
parent
a41033f150
commit
08040ef9c9
|
@ -8,10 +8,15 @@ import (
|
|||
"strings"
|
||||
)
|
||||
|
||||
var LISTENING_PORT string = ":1302"
|
||||
|
||||
func main() {
|
||||
ln, err := net.Listen("tcp", ":1302")
|
||||
if len(os.Args) != 1 {
|
||||
LISTENING_PORT = ":" + os.Args[1]
|
||||
}
|
||||
ln, err := net.Listen("tcp", LISTENING_PORT)
|
||||
catchErr(err)
|
||||
fmt.Printf("Listening on port 1302...\n")
|
||||
fmt.Printf("Listening on port %v...\n", strings.TrimLeft(LISTENING_PORT, ":"))
|
||||
|
||||
for {
|
||||
conn, err := ln.Accept()
|
||||
|
@ -27,7 +32,7 @@ func handleConn(conn net.Conn) {
|
|||
catchErr(err)
|
||||
fmt.Printf("Message received: %v", string(message))
|
||||
newMsg := strings.ToUpper(message)
|
||||
conn.Write([]byte(newMsg + "\n"))
|
||||
conn.Write([]byte(newMsg))
|
||||
}
|
||||
|
||||
func catchErr(err error) (errHappened bool) {
|
||||
|
|
Loading…
Reference in New Issue