java - cannot receive udp broadcast packet on android -
i trying receive udp packets being sent android machine.ii can receive same packets on java udp client program same not working on android. here code:
//main activity
public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); log.v("main activity", "intialized started"); list = (listview) findviewbyid(r.id.listview1); mainwifiobj = (wifimanager) getsystemservice(context.wifi_service); wifireciever = new wifiscanreceiver(); mainwifiobj.startscan(); log.v("main activity", "mainactivity started"); clientdatagramreceiver=new clientdatagramreceiver(); clientdatagramreceiver.start(); //clientdatagramreceiver class import java.io.ioexception; import java.net.datagrampacket; import java.net.datagramsocket; import java.net.inetaddress; import java.net.socketexception; import android.util.log; import android.widget.toast; public class clientdatagramreceiver extends thread { private datagramsocket datagramsocket = null; private boolean bkeeprunning = true; inetaddress serverip=null; public clientdatagramreceiver() { try { datagramsocket = new datagramsocket(7999); log.v("clientdatagramsender", "socket created"); } catch (socketexception e) { // todo auto-generated catch block e.printstacktrace(); log.v("clientdatagramsender", "socket unicast set"); } } public void run() { byte[] messagebytes = new byte[10]; datagrampacket packet = null; while(this.bkeeprunning) { packet = new datagrampacket(messagebytes, 10); log.d("clientdatagramreceiver", "receiving packet created"); try { datagramsocket.receive(packet); log.d("clientdatagramreceiver", "incoming packet received"); } catch (ioexception e) { e.printstacktrace(); } serverip=packet.getaddress(); log.d("clientdatagramreceiver", "ip address of remote sender: " + serverip.gethostaddress()); serveriphelper.setserverip(serverip); clientdatagramsender.killallthreads(); log.d("clientdatagramreceiver", "stopping broadcast service"); this.bkeeprunning = false; log.d("clientdatagramreceiver", "receiver closed"); } } }
it shows log till: "receiving packet created" doenot receive packets. suggestions appreciated. thanks
Comments
Post a Comment