Commits

Cédric Bonhomme committed 77b3750

Added ClientReader method.

Comments (0)

Files changed (1)

 }
 
 
+func ClientReader(client *Client) {
+    buffer := make([]byte, 2048)
+
+    for client.Read(buffer) {
+        if bytes.Equal(buffer, []byte("/quit")) {
+            client.Close()
+            break
+        }
+        Log("ClientReader received ", client.Name, "> ", string(buffer))
+        send := client.Name+"> "+string(buffer)
+        client.Outgoing <- send
+        for i := 0; i < 2048; i++ {
+            buffer[i] = 0x00
+        }
+    }
+
+    client.Outgoing <- client.Name + " has left chat"
+    Log("ClientReader stopped for ", client.Name)
+}
+
+
+
 
 func ClientHandler(conn net.Conn, ch chan string, clientList *list.List) {
     buffer := make([]byte, 1024)