MyGit

jmdns/jmdns

Fork: 192 Star: 581 (更新于 2024-11-22 19:56:39)

license: Apache-2.0

Language: Java .

Official home of the JmDNS library

最后发布版本: 3.6.0 ( 2024-11-08 05:44:55)

官方网址 GitHub网址

JmDNS


Version License Build

This Java implementation of multicast DNS enables both service discovery and registration, and is fully compatible with Apple's Bonjour.

Attribution

This library is licensed under the Apache License Version 2.0. Please see the file NOTICE.txt.

Arthur van Hoff avh@strangeberry.com

Rick Blair rickblair@mac.com

Kai Kreuzer kai@openhab.org

Usage

This is an implementation of multi-cast DNS in Java. It supports service discovery and service registration. It is fully interoperable with Apple's Bonjour.

Sample Code for Service Registration

import java.io.IOException;
import java.net.InetAddress;

import javax.jmdns.JmDNS;
import javax.jmdns.ServiceInfo;

public class ExampleServiceRegistration {

    public static void main(String[] args) throws InterruptedException {

        try {
            // Create a JmDNS instance
            JmDNS jmdns = JmDNS.create(InetAddress.getLocalHost());

            // Register a service
            ServiceInfo serviceInfo = ServiceInfo.create("_http._tcp.local.", "example", 1234, "path=index.html");
            jmdns.registerService(serviceInfo);

            // Wait a bit
            Thread.sleep(25000);

            // Unregister all services
            jmdns.unregisterAllServices();

        } catch (IOException e) {
            System.out.println(e.getMessage());
        }
    }
}

Sample code for Service Discovery

import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;

import javax.jmdns.JmDNS;
import javax.jmdns.ServiceEvent;
import javax.jmdns.ServiceListener;

public class ExampleServiceDiscovery {

    private static class SampleListener implements ServiceListener {
        @Override
        public void serviceAdded(ServiceEvent event) {
            System.out.println("Service added: " + event.getInfo());
        }

        @Override
        public void serviceRemoved(ServiceEvent event) {
            System.out.println("Service removed: " + event.getInfo());
        }

        @Override
        public void serviceResolved(ServiceEvent event) {
            System.out.println("Service resolved: " + event.getInfo());
        }
    }

    public static void main(String[] args) throws InterruptedException {
        try {
            // Create a JmDNS instance
            JmDNS jmdns = JmDNS.create(InetAddress.getLocalHost());

            // Add a service listener
            jmdns.addServiceListener("_http._tcp.local.", new SampleListener());

            // Wait a bit
            Thread.sleep(30000);
        } catch (UnknownHostException e) {
            System.out.println(e.getMessage());
        } catch (IOException e) {
            System.out.println(e.getMessage());
        }
    }
}

最近版本更新:(数据更新于 2024-11-22 11:34:17)

2024-11-08 05:44:55 3.6.0

2024-08-23 15:34:28 3.5.12

2024-08-07 20:59:14 3.5.11

2024-08-06 06:23:51 3.5.10

2023-12-06 16:09:50 3.5.9

2022-07-05 02:37:05 3.5.8

2021-05-29 04:06:42 3.5.7

2020-10-15 06:02:09 3.5.6

2018-12-04 22:03:47 jmdns-3.5.5

2018-04-12 23:39:37 jmdns-3.5.4

主题(topics):

mdns, multicast-dns, service-discovery, zeroconf

jmdns/jmdns同语言 Java最近更新仓库

2024-11-21 20:32:01 spring-projects/spring-boot

2024-11-21 09:44:43 Card-Forge/forge

2024-11-19 23:42:52 spring-projects/spring-authorization-server

2024-11-18 21:40:12 4379711/lol-helper

2024-11-16 22:50:41 xuxueli/xxl-job

2024-11-16 19:06:35 Stirling-Tools/Stirling-PDF