// Use Listen to start a server, and accept connections with Accept(). func ExampleListen() { ln, err := npipex.Listen(`\\.\pipe\mypipe`) if err != nil { // handle error } for { conn, err := ln.Accept() if err != nil { // handle error continue } // handle connection like any other net.Conn go func(conn net.Conn) { r := bufio.NewReader(conn) msg, err := r.ReadString('\n') if err != nil { // handle error return } fmt.Println(msg) }(conn) } }
func Listen(network, laddr string) (net.Listener, error) { if network == "npipe" { if !strings.HasPrefix(laddr, `\\.\pipe\`) { laddr = `\\.\pipe\` + laddr } return npipex.Listen(laddr) } else { return net.Listen(network, laddr) } }