1.android 設(shè)備在未有設(shè)備連接的時(shí)候,怎么判斷socket是未連接,如果使用API提供的isConnected()的方法會(huì)報(bào)一個(gè)空指針
2.當(dāng)socket連接的設(shè)備突然斷開怎么實(shí)時(shí)獲取socket的狀態(tài)
3在進(jìn)行socket通信的時(shí)候會(huì)出現(xiàn)可以發(fā)送數(shù)據(jù),卻收不到數(shù)據(jù),如果處理
小伙看你根骨奇佳,潛力無限,來學(xué)PHP伐。
Is the server enabled on your device? , if yes, then ServerSocket.accept()
方法是阻塞的,你的判斷代碼不要寫在這個(gè)方法成功前就創(chuàng)建好的其他線程內(nèi),要與ServerSocket.accept()
在同一線程或者在 ServerSocket.accept()
執(zhí)行后新開的線程內(nèi),以保證判斷方法也會(huì)被阻塞影響。 ——另外判斷連接狀態(tài)用Socket.isClosed()
.
There is no way to achieve complete real-time. You can look at the information on the heartbeat mechanism. Generally, this method of continuously sending simple data is used to determine whether the remote end is online.
Same as the heartbeat mechanism above, you can ask the receiving end to return a result mark to you after the data is sent successfully.