see properties of a JmDNS service in reciever

Help
helene
2011-09-19
2013-01-24
  • helene
    helene
    2011-09-19

    One way of creating JmDNS services is :

    ServiceInfo.create(type, name, port, weight, priority, props);

    where props is a Map which describes some propeties of the service. Does anybody have an example illustrating the use of theese properties, for instance how to use them in the reciever part. I've tried :

    Hashtable<String,String> settings = new Hashtable<String,String>();
    settings.put("host", "hhgh");
    settings.put("web_port", "hdhr");
    settings.put("secure_web_port", "dfhdyhdh");
    ServiceInfo info = ServiceInfo.create("_workstation._tcp.local.", "service6", 80, 0, 0, true, settings);
    but, then in a machine receiving this service, what can I do to see those properties?

    I would apreciate any help…

     
  • Pierre Frisch
    Pierre Frisch
    2011-09-19

    Properties are encoded in the text part of the service record. You can retrieve them using the accessor functions: ServiceInfo.getPropertyNames() and ServiceInfo.getPropertyString();

    Pierre

     
  • Pierre Frisch
    Pierre Frisch
    2011-09-19

    Your example is probably misleading. Host and port should not be encoded in the text portion as they are part of the standard value. If you have 2 services one secure and on non secure you should probably publish 2 services. The host will be resolved automatically and the port is the value in the definition of the service.

    My recommendation would be to have a text property with secure (yes/no) and publish 2 services service6 and service6secure

     
  • helene
    helene
    2011-09-20

    thanks for your quick reply, and sorry for the misleading example. Wah I want to do is much simpler, I want to create a new service in machine1, that have property X, and then I want to be able to see the property Xin machine2, which is seeing the service of machine1.
    I tried :

    service = ServiceInfo.create("_example._tcp.local.",  InetAddress.getLocalHost().getHostName(), 80, "property X");

    then in machine2, I have

    public void serviceAdded(final ServiceEvent e) {
            final String name = e.getName();
            String en = e.getInfo().getPropertyString(name);
            if (en == null){
            System.out.println("en == null");
            }
            else{
            System.out.println("en != null");
            }
            SwingUtilities.invokeLater(new Runnable() {
               ……
            });
            }

    the result is always en == null
    Also, when I use

    Enumeration<String> en = e.getInfo().getPropertyNames(), I get an empty Enumeration..

    What is wrong in my code?

     
  • helene
    helene
    2011-09-20

    well, name is not the proper thing to use with getPropertyString() (don't know how to use it exactly) but still getPropertyNames() gives an empty enumeration