client.go 698 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package main
  2. import (
  3. "errors"
  4. "math/rand"
  5. "net"
  6. "time"
  7. "github.com/cryptix/goremutake"
  8. "github.com/ftrvxmtrx/fd"
  9. )
  10. const path = "/tmp/sendMsgTest.sock"
  11. func main() {
  12. rand.Seed(time.Now().Unix())
  13. laddr, err := net.ResolveUnixAddr("unix", "")
  14. check(err)
  15. raddr, err := net.ResolveUnixAddr("unix", path)
  16. check(err)
  17. conn, err := net.DialUnix("unix", laddr, raddr)
  18. check(err)
  19. f, err := fd.Get(conn, 1, []string{"duh"})
  20. check(err)
  21. if len(f) < 1 {
  22. check(errors.New("not enough fds!"))
  23. }
  24. _, err = f[0].WriteString("Hello world!" + goremutake.Encode(uint(1024+rand.Intn(10000))))
  25. check(err)
  26. check(f[0].Close())
  27. }
  28. func check(err error) {
  29. if err != nil {
  30. panic(err)
  31. }
  32. }