mDNS Implemetaion for BlackBerry
mDNS is an UDP multicast version of DNS protocol, mainly used by Apple as service discovery protocol. So it’s used by iPhone with no problems. When I started creating BlackBerry version of it I’ve faced several challenges.
The first of all there is no open source implementation of mDNS for Java micro edition only for Java SE.
The second problem is that BlackBerry doesn’t support UDP multicast properly: multicasts can be sent, but can’t be received. Only UPD unicasts are supported.
So I had a lot of work to do. At the beginning I started to create a port of jmDNS for j2me. It’s an open source implementation of mDNS protocol for Java SE. jmDNS uses a lot of Java 1.5+ features that are not supported by j2me. Such as enums, generics, thread safe collections (ex. ConcurrentHashMap).
So the solution was to port a part of jmDNS that implements DNS records parsing and building. And create an implementation of other required logic: receiving mDNS records. I’ve wasted a lot of time trying to port jmDNS version 3.1. It’s unstable version with a lot of bugs that were fixed in 3.1.4 release (current version).
To fix problem with UDP Multicast on BlackBerry I’ve patched jmDNS to send UDP unicast responses back to BlackBerry devices. It required only some small changes in sources to achieve that.
The example of usage :
package com.hellowebapps.tests;
import javax.jmdns.IServiceInfoListener;
import javax.jmdns.ServiceInfo;
import javax.jmdns.impl.JmDNSImpl;
import javax.jmdns.impl.network.j2me.NetworkLayerImpl;
public class ExampleServiceResolver {
JmDNSImpl jmDNS_;
public final static String EXAMPLE_SERVICE_TYPE = "_tcp.local.";
public final static String EXAMPLE_SERVICE_NAME =
"exampleService." + EXAMPLE_SERVICE_TYPE;
public ExampleServiceResolver()
{
ServiceInfoListenerImpl listener = new
ServiceInfoListenerImpl(EXAMPLE_SERVICE_TYPE);
String[] serviceTypes = new String[] {
listener.getServiceType()
};
IServiceInfoListener[] listeners = new IServiceInfoListener []{
listener
};
jmDNS_ = new JmDNSImpl(
serviceTypes,
listeners,
new NetworkLayerImpl()
);
}
public void close()
{
jmDNS_.close();
}
public ServiceInfo[] getServices()
{
return jmDNS_.getServicesList(EXAMPLE_SERVICE_TYPE);
}
private class ServiceInfoListenerImpl
implements IServiceInfoListener
{
String type_;
public ServiceInfoListenerImpl(String type)
{
type_ = type;
}
public String getServiceType() {
return type_;
}
public void onChange(ServiceInfo[] actualList) {
/* Receiving list of actual services */
}
}
}
Sources :
jmDNS port for BlackBerry: j2meMDNS-0.1
jmDNS patched: jmdns-1.0-Pathed
-
[...] This post was mentioned on Twitter by HelloWebApps, Andriy Mykhalyuk. Andriy Mykhalyuk said: Blog post: mDNS implementation for #Blackberry : http://bit.ly/bNvCWP #j2me #java #RIM #dns [...]



Nifty! I’m looking forward to giving this a spin. It’s not clear from your write up which version(s) of JmDNS you patched up.
Thanks!
The pathed version is “jmdns 1.0 Final”.
Thanks,
Volodia
Hi , i tried to implement to discover for devices supporting ipp protocol using service Type “_ipp._tcp.local.” . i implement using your library j2meMDNS-0.1. i implement for blackberry .
My source code is
//service type strings
String[] serviceTypes = {“_ipp._tcp.local.”};
//service type strings
String[] serviceTypes = {“_ipp._tcp.local.”};
//inititalize service listener
MyServiceListener listener = new MyServiceListener();
//initialize listeners array
IServiceInfoListener[] listeners = {listener};
//initialize network layer
NetworkLayerImpl nl = new NetworkLayerImpl();
//initialize jmdns
jmdns = new JmDNSImpl(serviceTypes,listeners, nl);
System.out.println(“Done”);//inititalize service listener
MyServiceListener listener = new MyServiceListener();
//initialize listeners array
IServiceInfoListener[] listeners = {listener};
//initialize network layer
NetworkLayerImpl nl = new NetworkLayerImpl();
//initialize jmdns
jmdns = new JmDNSImpl(serviceTypes,listeners, nl);
System.out.println(“Done”);
but i did not fin any success .
could you please help me out how do i ned to implement.
i you have any source code , please share it with ..
waiting for response
Thanks in advance.