address=InetAddress.getByName(url);inti=0;byte[]receiveByte=newbyte[1316];Log.i("2015-6-3","threadrunning");dataPacket=newDatagramPacket(receiveByte,receiveByte.length);if(address==NULL){try{dataSocket=newDatagramSocket(PORT);}catch(SocketExceptione1){//TODOAuto-generatedcatchblockLog.i("2015-6-3","portcannotopen");e1.printStackTrace();}}else{try{dataSocket=newDatagramSocket(PORT,address);}catch(SocketExceptione1){//TODOAuto-generatedcatchblockLog.i("2015-6-8","portcannotopen");e1.printStackTrace();}}while(true){try{dataSocket.receive(dataPacket);}catch(IOExceptione){//TODOAuto-generatedcatchblockLog.i("2015-6-3","packetreceivefailed");e.printStackTrace();}相關(guān)代碼如上,其中UDP只是監(jiān)聽端口,數(shù)據(jù)接收沒有問題。但是加上IP就直接閃退到上一個(gè)activity,求解答。InetAddress.getByName(url)內(nèi)的url是“239.255.x.x”格式的----------分割線-------------經(jīng)過修改后的代碼swi=1;try{dataaddr=newMulticastSocket(port);}catch(IOExceptione1){//TODOAuto-generatedcatchblocke1.printStackTrace();}try{address=InetAddress.getByName(url);}catch(UnknownHostExceptione){//TODOAuto-generatedcatchblocke.printStackTrace();}try{dataaddr.joinGroup(address);}catch(IOExceptione){//TODOAuto-generatedcatchblocke.printStackTrace();}try{dataaddr.receive(dataPacket);}catch(IOExceptione){//TODOAuto-generatedcatchblockLog.i("2015-6-3","packetreceivefailed");e.printStackTrace();}.........這時(shí)出現(xiàn)了一個(gè)bug,W/ContextImpl(1909):Callingamethodinthesystemprocesswithoutaqualifieduser:android.app.ContextImpl.sendBroadcast:1168com.android.internal.policy.impl.PhoneWindowManager.interceptKeyBeforeQueueing:4109com.android.server.wm.InputMonitor.interceptKeyBeforeQueueing:357com.android.server.input.InputManagerService.interceptKeyBeforeQueueing:1352dalvik.system.NativeStart.run:-2不知道有沒有解,PS:VLC或者ffmpeg都是用c接收這種UDP包的
android udp接收
藍(lán)山帝景
2019-04-10 20:49:04