1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
| func main() {
service := ":8082" tcpAddr, err := net.ResolveTCPAddr("tcp4", service) checkError(err)
listener, err := net.ListenTCP("tcp", tcpAddr) checkError(err)
for { conn, err := listener.Accept() if err != nil { continue } handleClient(conn) conn.Close() } }
func handleClient(conn net.Conn) { var buf [512]byte for { n, err := conn.Read(buf[0:]) if err != nil { return }
_, err2 := conn.Write(buf[0:n]) if err2 != nil { return } } }
|