From 08040ef9c96e62c1cd1c041acd2c2a0149202b06 Mon Sep 17 00:00:00 2001 From: raul Date: Sun, 10 Mar 2024 09:21:02 +0100 Subject: [PATCH] Added ability to use custom ports --- sockets/main.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/sockets/main.go b/sockets/main.go index df4a669..912ed84 100644 --- a/sockets/main.go +++ b/sockets/main.go @@ -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) {