Last active
August 9, 2020 11:55
-
-
Save kirk91/688cf5a2b8fb8dcc879f420552ff827f to your computer and use it in GitHub Desktop.
TCP Echo over abstract 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" | |
) | |
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