Commits

Cédric Bonhomme committed 03ba8a0

Parse command line with Flag().

  • Participants
  • Parent commits 60f8955

Comments (0)

Files changed (1)

         "net"
         "container/list"
         "bytes"
+        "flag"
 )
 
 
 
 // Main: Starts a TCP server and waits infinitely for connections
 func main() {
+
+    address := ""
+    port := ""
+
+    flag.Parse()
+    argv := flag.Args()
+    if len(argv) == 0 {
+        address = "127.0.0.1"
+        port = "9988"
+    } else {
+        address = argv[0]
+        port = argv[1]
+    }
+    service := address + ":" + port
+
+
     Log("Hello Server!")
 
     clientList := list.New()
     in := make(chan string)
     go IOHandler(in, clientList)
 
-    address := "127.0.0.1"
-    port := "9988"
-    service := address + ":" + port
-
     tcpAddr, error := net.ResolveTCPAddr("tcp", service)
     if error != nil {
         Log("Error: Could not resolve address")