Commits

Cédric Bonhomme committed 6d83d10

Added Client Handler method, testing...

Comments (0)

Files changed (1)

 
 
 
+func ClientHandler(conn net.Conn, ch chan string, clientList *list.List) {
+    buffer := make([]byte, 1024)
+    bytesRead, error := conn.Read(buffer)
+    if error != nil {
+        Log("Client connection error: ", error)
+    }
+
+    name := string(buffer[0:bytesRead])
+    newClient := &Client{name, make(chan string), ch, conn, make(chan bool), clientList}
+
+    go ClientSender(newClient)
+    go ClientReader(newClient)
+    clientList.PushBack(*newClient)
+    ch <-string(name + " has joined the chat")
+}
 
 // Main: Starts a TCP server and waits infinitely for connections
 func main() {