Unixgram example

642 views
Skip to first unread message

Taru Karttunen

unread,
Jan 27, 2011, 8:02:18 AM1/27/11
to golang-nuts
Hello

Has anyone gotten reading from unixgram sockets working?
I keep getting "address family not supported by protocol"
with ReadFrom. Any working example would be appreciated.

- Taru Karttunen

Albert Strasheim

unread,
Jan 27, 2011, 12:05:03 PM1/27/11
to golang-nuts
Hello

On Jan 27, 3:02 pm, Taru Karttunen <tar...@taruti.net> wrote:
> Has anyone gotten reading from unixgram sockets working?
> I keep getting "address family not supported by protocol"
> with ReadFrom. Any working example would be appreciated.

Are you on Linux? Does ./all.bash pass for you? If so, at least we
know that the code more or less works on your system.

Take a look at

http://code.google.com/p/go/source/browse/src/pkg/net/server_test.go

for some example code.

Alternatively, could you provide a small example program that
reproduces the error?

Regards

Albert

Dave Cheney

unread,
Jan 27, 2011, 4:13:53 PM1/27/11
to Albert Strasheim, golang-nuts
Hi Taru,

Here is a quick snipped cribbed from a project i'm working on.
CM_SOCKET is an environment variable that points to the location of
the unix socket on disk.

// start unix cli
addr, err := net.ResolveUnixAddr("unix", os.Getenv("CM_SOCKET"))
if err != nil {
log.Exitf("Unable to open unix socket [%s], %s",
os.Getenv("CM_SOCKET"), err)
}
listener, err := net.ListenUnix("unix", addr)
if err != nil {
log.Exit("Unable to create new CLI Listener on ", addr, err)
}
defer listener.Close()
for {
conn, err := listener.Accept()
if err != nil {
log.Print("Unable to accept Socket connection", err)
}
worker := &CliWorker{
conn: conn,
manager: manager,
}
go worker.main()
}

Cheers

Dave

Reply all
Reply to author
Forward
0 new messages