adding client and url
This commit is contained in:
parent
cee9fedf2a
commit
d7b69ef511
2 changed files with 41 additions and 0 deletions
2
app.go
2
app.go
|
@ -1,5 +1,7 @@
|
|||
package main
|
||||
|
||||
// drawn from https://stackoverflow.com/questions/2886719/unix-sockets-in-go
|
||||
|
||||
import (
|
||||
"log"
|
||||
"net"
|
||||
|
|
39
client.go
Normal file
39
client.go
Normal file
|
@ -0,0 +1,39 @@
|
|||
// +build ignore
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"io"
|
||||
"log"
|
||||
"net"
|
||||
"time"
|
||||
)
|
||||
|
||||
func reader(r io.Reader) {
|
||||
buf := make([]byte, 1024)
|
||||
for {
|
||||
n, err := r.Read(buf[:])
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
println("Client got:", string(buf[0:n]))
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
c, err := net.Dial("unix", "/tmp/echo.sock")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer c.Close()
|
||||
|
||||
go reader(c)
|
||||
for {
|
||||
_, err := c.Write([]byte("hi"))
|
||||
if err != nil {
|
||||
log.Fatal("write error:", err)
|
||||
break
|
||||
}
|
||||
time.Sleep(1e9)
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue