java - How to find specific devices(phone) in a network using nsd? -
i need create group of specific devices in network such in shareit app(the group share). new nsd , tried latest sample code nsdchat google. app has 4 buttons:
- register
- discover
- connect
- send
i first tap on "register" in device , tap "discover" in device b. doesn't work. after searching found 1 answer stating following change in nsdhelper
public void initializediscoverylistener() { mdiscoverylistener = new nsdmanager.discoverylistener() { @override public void ondiscoverystarted(string regtype) { log.d(tag, "service discovery started"); } @override public void onservicefound(nsdserviceinfo service) { log.d(tag, "service discovery success" + service); if (!service.getservicetype().equals(service_type)) { log.d(tag, "unknown service type: " + service.getservicetype()); } else if (service.getservicename().equals(mservicename)) { log.d(tag, "same machine: " + mservicename); } else if (service.getservicename().contains(mservicename)){ //here change, instead of using class variable creates new resolvelistener. mnsdmanager.resolveservice(service, new nsdmanager.resolvelistener(){ @override public void onresolvefailed(nsdserviceinfo serviceinfo, int errorcode) { log.e(tag, "resolve failed" + errorcode); } @override public void onserviceresolved(nsdserviceinfo serviceinfo) { log.e(tag, "resolve succeeded. " + serviceinfo); if (serviceinfo.getservicename().equals(mservicename)) { log.d(tag, "same ip."); return; } mservice = serviceinfo; } }); } }
following log of device (only) when tap register , device b tap discover
09-10 21:24:28.440 28618-28618/lemonlabs.test d/nsdchat: creating chat activity 09-10 21:24:28.520 28618-28620/lemonlabs.test d/dalvikvm: gc_concurrent freed 549k, 16% free 8911k/10556k, paused 5ms+7ms, total 74ms 09-10 21:24:28.530 28618-28618/lemonlabs.test d/nsdchat: starting. 09-10 21:24:28.530 28618-3757/lemonlabs.test d/chatconnection: serversocket created, awaiting connection 09-10 21:24:28.530 28618-28618/lemonlabs.test d/nsdchat: resuming. 09-10 21:24:28.540 28618-3758/lemonlabs.test d/nsdhelper: service discovery started 09-10 21:24:28.560 28618-28618/lemonlabs.test w/khrn_client: init_window num_buffers 3 min undequeued buffers 1 09-10 21:24:28.570 28618-28618/lemonlabs.test w/khrn_client: init_window window 0x508a3be8, 480x800 hinttransform 0x0 do_pre 1 09-10 21:24:50.742 28618-3758/lemonlabs.test d/nsdhelper: service registered: nsdchat 09-10 21:24:50.992 28618-3758/lemonlabs.test d/nsdhelper: service discovery successname: nsdchattype: _http._tcp.host: nullport: 0txtrecord: null 09-10 21:24:50.992 28618-3758/lemonlabs.test d/nsdhelper: same machine: nsdchat 09-10 21:24:51.002 28618-3758/lemonlabs.test d/nsdhelper: service discovery successname: nsdchattype: _http._tcp.host: nullport: 0txtrecord: null 09-10 21:24:51.002 28618-3758/lemonlabs.test d/nsdhelper: same machine: nsdchat
following when press button:
09-10 21:26:04.464 28618-28618/lemonlabs.test d/nsdchat: pausing. 09-10 21:26:04.464 28618-3758/lemonlabs.test i/nsdhelper: discovery stopped: _http._tcp. 09-10 21:26:04.534 28618-28618/lemonlabs.test w/iinputconnectionwrapper: showstatusicon on inactive inputconnection 09-10 21:26:04.604 28618-28618/lemonlabs.test d/nsdchat: being stopped. 09-10 21:26:04.614 28618-3758/lemonlabs.test d/nsdhelper: service unregistered: nsdchat 09-10 21:26:04.614 28618-3757/lemonlabs.test e/chatconnection: error creating serversocket: java.net.socketexception: socket closed @ libcore.io.posix.accept(native method) @ libcore.io.blockguardos.accept(blockguardos.java:55) @ java.net.plainsocketimpl.accept(plainsocketimpl.java:98) @ java.net.serversocket.implaccept(serversocket.java:202) @ java.net.serversocket.accept(serversocket.java:127) @ lemonlabs.test.chatconnection$chatserver$serverthread.run(chatconnection.java:113) @ java.lang.thread.run(thread.java:856) 09-10 21:26:04.614 28618-3757/lemonlabs.test w/system.err: java.net.socketexception: socket closed 09-10 21:26:04.614 28618-3757/lemonlabs.test w/system.err: @ libcore.io.posix.accept(native method) 09-10 21:26:04.614 28618-3757/lemonlabs.test w/system.err: @ libcore.io.blockguardos.accept(blockguardos.java:55) 09-10 21:26:04.614 28618-3757/lemonlabs.test w/system.err: @ java.net.plainsocketimpl.accept(plainsocketimpl.java:98) 09-10 21:26:04.614 28618-3757/lemonlabs.test w/system.err: @ java.net.serversocket.implaccept(serversocket.java:202) 09-10 21:26:04.614 28618-3757/lemonlabs.test w/system.err: @ java.net.serversocket.accept(serversocket.java:127) 09-10 21:26:04.614 28618-3757/lemonlabs.test w/system.err: @ lemonlabs.test.chatconnection$chatserver$serverthread.run(chatconnection.java:113) 09-10 21:26:04.614 28618-3757/lemonlabs.test w/system.err: @ java.lang.thread.run(thread.java:856) 09-10 21:26:04.614 28618-28618/lemonlabs.test d/nsdchat: being destroyed.
i need device search other devices(providing service) on network , connect of them (without using ip).
Comments
Post a Comment