Skip to content

Instantly share code, notes, and snippets.

@kirk91
Last active August 9, 2020 11:55
Show Gist options
  • Save kirk91/688cf5a2b8fb8dcc879f420552ff827f to your computer and use it in GitHub Desktop.
Save kirk91/688cf5a2b8fb8dcc879f420552ff827f to your computer and use it in GitHub Desktop.
TCP Echo over abstract unix domain socket
package main
import (
"io"
"net"
)
func main() {
// '@' indicates the socket held in an abstract namespace
// which doesn't belong to a file in the filesystem
udsPath := "@tcp-unix.sock"
ln, err := net.Listen("unix", udsPath)
if err != nil {
panic(err)
}
defer ln.Close()
for {
conn, err := ln.Accept()
if err != nil {
panic(err)
}
// handle conn
go func(conn net.Conn) {
defer conn.Close()
io.Copy(conn, conn)
}(conn)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment