Skip to content

Instantly share code, notes, and snippets.

@kirk91
Last active August 9, 2020 09:33
Show Gist options
  • Save kirk91/a6c8f6d07c754980b69ffc42127812a2 to your computer and use it in GitHub Desktop.
Save kirk91/a6c8f6d07c754980b69ffc42127812a2 to your computer and use it in GitHub Desktop.
TCP Echo over unix domain socket
package main
import (
"io"
"net"
"os"
)
func main() {
udsPath := "/tmp/tcp-unix.sock"
os.Remove(udsPath) //nolint:errcheck
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