conn, err := net.Dial("tcp", "example.com:80") if err != nil { panic(err) } tcpconn := conn.(*net.TCPConn) // Disable Nagle algorithm tcpconn.SetNoDelay(true)
listener, err := net.Listen("tcp", ":8000") if err != nil { panic(err) } for { conn, err := listener.Accept() if err != nil { panic(err) } tcpconn := conn.(*net.TCPConn) // Enable Nagle algorithm tcpconn.SetNoDelay(false) // Handle the conneciton }This example listens on port 8000 for incoming TCP connections. When a connection is accepted, the NoDelay option is set to 'false' (enabling the Nagle algorithm) and the connection is handled. Package: net.