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();}相关代码如上,其中UDP只是监听端口,数据接收没有问题。但是加上IP就直接闪退到上一个activity,求解答。InetAddress.getByName(url)内的url是“239.255.x.x”格式的----------分割线-------------经过修改后的代码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();}.........这时出现了一个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包的
海绵宝宝撒
猛跑小猪
相关分类