Go language Echo server method

  • 2020-05-24 05:42:11
  • OfStack

This article illustrates the Go language Echo server approach. Share with you for your reference. The details are as follows:

package main
import (
    "net"
    "io"
)
func main() {
    serv, e := net.Listen("tcp", ":12345")
    if e != nil {
        panic(e)
    }
    defer serv.Close()
    for {
        conn, ce := serv.Accept()
        if ce != nil {
            break
        }
        go func(c net.Conn) {
            io.Copy(c, c)
            c.Close()
        }(conn)
    }
}

I hope this article has been helpful to your programming of Go language.


Related articles: