This repository has been archived on 2024-04-07. You can view files and clone it, but cannot push or open issues or pull requests.
unix-sockets-test-go/server.go

41 lines
582 B
Go

package main
import (
"log"
"net"
)
func echoServer(c *net.UnixConn) {
for {
buf := make([]byte, 1024)
nr, err := c.Read(buf)
if err != nil {
return
}
data := buf[:nr]
println("<", string(data))
_, err = c.Write(data)
if err != nil {
log.Fatalln("Write error:", err)
}
}
}
func connectServer(addr *net.UnixAddr) {
unixSock, err := net.ListenUnix("unix", addr)
if err != nil {
log.Panic(err)
}
defer unixSock.Close()
for {
fd, err := unixSock.AcceptUnix()
if err != nil {
log.Fatalln("Accept error:", err)
}
go echoServer(fd)
}
}