ipld-eth-server/vendor/gopkg.in/natefinch/npipe.v2/example_windows_test.go
Matt K 293dd2e848 Add vendor dir (#16) (#4)
* Add vendor dir so builds dont require dep

* Pin specific version go-eth version
2018-01-29 13:44:18 -06:00

54 lines
945 B
Go

package npipe_test
import (
"bufio"
"fmt"
"net"
"gopkg.in/natefinch/npipe.v2"
)
// Use Dial to connect to a server and read messages from it.
func ExampleDial() {
conn, err := npipe.Dial(`\\.\pipe\mypipe`)
if err != nil {
// handle error
}
if _, err := fmt.Fprintln(conn, "Hi server!"); err != nil {
// handle error
}
r := bufio.NewReader(conn)
msg, err := r.ReadString('\n')
if err != nil {
// handle eror
}
fmt.Println(msg)
}
// Use Listen to start a server, and accept connections with Accept().
func ExampleListen() {
ln, err := npipe.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)
}
}