Last active
August 9, 2020 09:33
-
-
Save kirk91/a6c8f6d07c754980b69ffc42127812a2 to your computer and use it in GitHub Desktop.
TCP Echo over unix domain socket
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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