以下内容之一:dns.server.com不是有效的DNS服务器,没有_sip._udp的SRV记录,DNS服务在端口53(标准DNS端口)上没有响应,或者您的Java代码错误.

要诊断DNS服务器问题,您可以尝试使用主机-t SRV _sip._udp.server.com dns.server.com或dig @ dns.server.com -t SRV _sip._udp.server.com确认服务器正常运行.

如果host或dig返回期望的条目,请尝试对代码进行以下更改:

更改:

env.put("java.naming.provider.url", "dns://dns.server.com");

至:

env.put("java.naming.provider.url", "dns:");

(即,仅使用操作系统的标准DNS解析度)

更改:

ctx.getAttributes("_sip._udp", new String [] { "SRV" });

至:

ctx.getAttributes("_sip._udp.domain.com", new String [] { "SRV" });

因为SRV记录需要一个域名才能搜索,所以您最终得到:

Hashtable env = new Hashtable();

env.put("java.naming.factory.initial", "com.sun.jndi.dns.DnsContextFactory");

DirContext ctx = new InitialDirContext(env);

Attributes attributes = ctx.getAttributes("_sip._udp.domain.com", new String [] { "SRV" });

return attributes;