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