fromkeith / gossdp

golang implementation of a simple ssdp server/client
13 stars 8 forks source link

Trying to run it for a first time in Mac OSX #5

Open jsdario opened 7 years ago

jsdario commented 7 years ago

Hi here!

Much appreciation for your work. I am mostly new to golang and I am struggling with the following error:

join group 8 setsockopt: address family not supported by protocol family

But my code is rather simple. I tried to look it up online but found nothing so far, and think it might be caused by a OS flag that is missing in this package. If I am wrong, please correct me:

Here is the sample:

package main

import (
  "log"
  "github.com/fromkeith/gossdp"
)

func main() {
  log.Println("Running, SSDP advertiser...\n")

  s, err := gossdp.NewSsdp(nil)

  if err != nil {
    log.Println("Error creating ssdp server: ", err)
    return
  }

  // Define the service we want to advertise
  serverDef := gossdp.AdvertisableServer{
    ServiceType: "bigfoot:all", // define the service type
    DeviceUuid: "hh0c2981-0029-44b7-4u04-27f187aecf78", // make this unique!
    Location: "http://192.168.1.1:8080", // this is the location of the service we are advertising
    MaxAge: 3600, // Max age this advertisment is valid for
  }

  // Call stop  when we are done
  defer s.Stop()

  // run! this will block until stop is called. so open it in a goroutine here
  go s.Start()

  // start advertising it!
  s.AdvertiseServer(serverDef)
}
fromkeith commented 7 years ago

Hi,

I haven't tested this code on a mac... but my guess is this file has the issue: https://github.com/fromkeith/gossdp/blob/master/broadcast_unix.go

Probably around line 86.

That section of code is looking at all your attached network cards, and trying to join the desired multicast group.

Is the code crashing for you? Or are you not seeing any multicast packets being emitted? Or does it exit with the error Unable to find a compatible network interface!?

jsdario commented 7 years ago

Hi,

thanks for replying!

The code crashes for me with the error above mentioned:

join group 8 setsockopt: address family not supported by protocol family
fromkeith commented 7 years ago

Can you try add a sleep to the end of the func? That executable immediately exits and stops the server. Which may cause some weirdness...

Eg.

time.Sleep(30 * time.Second)
hazcod commented 6 years ago

Same for me on macOS.