[avahi] Publish service and service discovery with one poll loop
Alin Rus
netblock at gmail.com
Sun May 27 14:13:14 PDT 2012
Hello,
I'm considering using Avahi for a project targeting embedded Linux.
Basically what I'm trying to do is publish a service from my
application and from the same application discover other nodes that
have published the same service over the LAN.
As far as I know I can get away with only using libavahi-core,
libavahi-daemon and libdaemon. There won't be an Avahi service running
on that platform.
I was looking at core-browse-services.c and core-publish-services.c
and here are a couple of questions:
1) Is it possible to bypass the poll loop for service discovery and
just get the hosts whenever I need?
2) While looking at the examples is not clear to me whether is
possible to publish a service and do service discovery from the same
app. I compiled core-browse-services and core-publish-services and I
get the following warning
*** WARNING: Detected another IPv4 mDNS stack running on this host.
This makes mDNS unreliable and is thus not recommended. ***
3) Would this be a valid solution for publishing and discovering
services from the same app?
if (!(simple_poll = avahi_simple_poll_new())) {
fprintf(stderr, "Failed to create simple poll object.\n");
goto fail;
}
name = avahi_strdup("SOME_SERVICE");
/* Let's set the host name for this server. */
avahi_server_config_init(&config);
config.publish_hinfo = 0;
config.publish_addresses = 0;
config.host_name = avahi_strdup("my_host");
config.publish_workstation = 0;
config.publish_domain = 0;
/* Allocate a new server */
server = avahi_server_new(avahi_simple_poll_get(simple_poll),
&config, server_callback, NULL, &error);
/* Free the configuration data */
avahi_server_config_free(&config);
/* Check wether creating the server object succeeded */
if (!server) {
fprintf(stderr, "Failed to create server: %s\n", avahi_strerror(error));
goto fail;
}
/* Create the service browser */
if (!(sb = avahi_s_service_browser_new(server, AVAHI_IF_UNSPEC,
AVAHI_PROTO_UNSPEC, "_http._tcp", NULL, 0, browse_callback, server)))
{
fprintf(stderr, "Failed to create service browser: %s\n",
avahi_strerror(avahi_server_errno(server)));
goto fail;
}
/* Run the main loop */
avahi_simple_poll_loop(simple_poll);
Basically I've combined the two examples.
Regards,
--
Alin Rus
O< ascii ribbon campaign - stop html mail - www.asciiribbon.org
More information about the avahi
mailing list