Java 判断socket的连接状态
伊谢尔伦
伊谢尔伦 2017-04-17 17:37:56
0
1
581

1.android 设备在未有设备连接的时候,怎么判断socket是未连接,如果使用API提供的isConnected()的方法会报一个空指针

2.当socket连接的设备突然断开怎么实时获取socket的状态

3在进行socket通信的时候会出现可以发送数据,却收不到数据,如果处理

伊谢尔伦
伊谢尔伦

小伙看你根骨奇佳,潜力无限,来学PHP伐。

reply all(1)
巴扎黑
  1. Is the server enabled on your device? , if yes, then ServerSocket.accept()方法是阻塞的,你的判断代码不要写在这个方法成功前就创建好的其他线程内,要与ServerSocket.accept()在同一线程或者在 ServerSocket.accept() 执行后新开的线程内,以保证判断方法也会被阻塞影响。 ——另外判断连接状态用Socket.isClosed().

  2. 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.

  3. 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.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!