Hi,
I updated code like this. now I can use the same handleConnection both server and client, the only difference is the content of message which is read or written. ``` func handleConnection(conn net.Conn) { defer conn.Close() msgID := 0 reader := bufio.NewReader(conn) writer := bufio.NewWriter(conn) readChannel := make(chan struct{}) writeChannel := make(chan struct{}) go func() { for { line, err := reader.ReadString('\n') if err != nil { log.Println(err, line) close(readChannel) break } fmt.Print(line) } }() go func() { for { msgID++ msg := fmt.Sprintf("msg from server with msgID: %d\n", msgID) if n, err := writer.WriteString(msg); err != nil { log.Println(err, n) close(writeChannel) break } writer.Flush() } }() for { if _, ok := <-readChannel; !ok { break } if _, ok := <-writeChannel; !ok { break } } } ``` -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/tencent_26860F11E667045B63D819FB4C9EE4C9C40A%40qq.com.