0

JmDNSサービスを作成する1つの方法は次のとおりです。

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

ここで、propsは、サービスのいくつかのプロパティを説明するマップです。誰かがこれらのプロパティの使用法を説明する例を持っていますか?たとえば、受信者の部分でそれらを使用する方法。私はもう試した :

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);

しかし、このサービスを受けているマシンで、これらのプロパティを表示するにはどうすればよいですか?

私はどんな助けにも感謝します...

4

2 に答える 2

0

これが尋ねられてからしばらく経ちましたが、同じ質問がありました。元の質問の 1 つの問題は、ホストとポートをテキスト フィールドに入力してはならないということです。この場合、実際には 1 つはセキュアでもう 1 つはセキュアでない (またはサブタイプを使用する) 2 つのサービス タイプが必要です。

以下は、実行中のワークステーション サービスのリストを取得する不完全な例です。

ServiceInfo[] serviceInfoList = jmdns.list("_workstation._tcp.local.");
if(serviceInfoList != null) {
  for (int index = 0; index < serviceInfoList.length; index++) {
    int port = serviceInfoList[index].getPort();
    int priority = serviceInfoList[index].getPriority();
    int weight = serviceInfoList[index].getWeight();
    InetAddress address = serviceInfoList[index].getInetAddresses()[0];
    String someProperty = serviceInfoList[index].getPropertyString("someproperty");

    // Build a UI or use some logic to decide if this service provider is the
    // one you want to use based on prority, properties, etc.
    ...
  }
}

JmDNS の実装方法により、特定のタイプでの list() への最初の呼び出しは遅くなります (数秒) が、その後の呼び出しはかなり高速になります。サービスのプロバイダーは info.setText(settings) を呼び出すことでプロパティを変更でき、変更はリスナーに自動的に伝達されます。

于 2012-07-25T18:04:47.510 に答える