第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

android udp接收

android udp接收

藍(lán)山帝景 2019-04-10 20:49:04
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包的
查看完整描述

2 回答

?
萬千封印

TA貢獻(xiàn)1891條經(jīng)驗(yàn) 獲得超3個(gè)贊

MulticastSocketdataaddr=newMulticastSocket(1234);InetAddressaddress=InetAddress.getByName("239.0.0.1");dataaddr.joinGroup(address);byte[]receiveByte=newbyte[1316];dataPacket=newDatagramPacket(receiveByte,receiveByte.length);try{dataaddr.receive(dataPacket);}catch(IOExceptione){//TODOAuto-generatedcatchblockLog.i("2015-6-3","packetreceivefailed");e.printStackTrace();}以上為解決辦法
查看完整回答
反對(duì) 回復(fù) 2019-04-10
?
ITMISS

TA貢獻(xiàn)1871條經(jīng)驗(yàn) 獲得超8個(gè)贊

DatagramSocket(intaPort,InetAddressaddr)這里的addr只能綁定本機(jī)的IP,你給的IP恐怕不是Android機(jī)器自己的IP吧。
如果addr不是本機(jī)IP,newDatagramSocket(PORT,address)會(huì)拋異常,從而導(dǎo)致dataSocket==null,后面你在dataSocket.receive調(diào)用時(shí)沒有捕捉NullPointerException,所以直接掛掉了。
                            
查看完整回答
反對(duì) 回復(fù) 2019-04-10
  • 2 回答
  • 0 關(guān)注
  • 450 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)