conn, err := net.Dial("tcp", "google.com:80") if err != nil { fmt.Println("Error connecting:", err) return } err = conn.SetWriteBuffer(1024) if err != nil { fmt.Println("Error setting write buffer:", err) return }
ln, err := net.Listen("tcp", ":8080") if err != nil { fmt.Println("Error listening:", err) return } defer ln.Close() for { conn, err := ln.Accept() if err != nil { fmt.Println("Error accepting:", err) continue } err = conn.SetWriteBuffer(2048) if err != nil { fmt.Println("Error setting write buffer:", err) conn.Close() continue } go handleConnection(conn) }This example sets the write buffer of a TCP connection to 2048 bytes for each client that connects to a TCP server listening on port 8080. Both examples are part of the Go standard library net package.