4
2

More than 3 years have passed since last update.

Go でプロセス間通信

Last updated at Posted at 2020-04-27

MS が https://github.com/Microsoft/go-winio を公開しているので、これを使う。
以下がサンプル

server.go
import (
    "fmt"
    "io/ioutil"

    "github.com/Microsoft/go-winio"
)

func main() {
    pipeConfig := winio.PipeConfig{
        SecurityDescriptor: "S:(ML;;NW;;;LW)D:(A;;0x12019f;;;WD)", // SDDL Everyone
        InputBufferSize:    4096,
        OutputBufferSize:   4096,
    }

    listener, _ := winio.ListenPipe(`\\.\pipe\my-named-pipe`, &pipeConfig)
    defer listener.Close()

    for {
        conn, _ := listener.Accept()
        defer conn.Close()

        bytes, _ := ioutil.ReadAll(conn)
        fmt.Println(string(bytes))
    }
}
client.go
import (
    "github.com/Microsoft/go-winio"
)

func main() {
    conn, err := winio.DialPipe(`\\.\pipe\my-named-pipe`, nil)

    if conn != nil && err == nil {
        defer conn.Close()

        conn.Write([]byte("Hello, world!"))
    }
}
4
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
2