我不得不创建必须监听传入连接的Android服务器应用程序。它是非根应用程序,它监听随机高端口。代码很简单,并且在桌面Java上非常出色,它只是侦听端口并实现非常简单的自定义请求/响应协议。然而,我发现即使Android应用程序现在都在accept
方法(即它应该等待传入连接),但由于任何原因,我经常发现连接超时。Android服务器:为什么它随机超时传入连接?
我发现有时甚至系统应用程序(例如ADB服务器)都会定期无限期地超时传入连接。例如见paping
输出:
paping -p 5555 192.168.0.105
paping v1.5.5 - Copyright (c) 2011 Mike Lovell
Connecting to 192.168.0.105 on TCP 5555:
Connection timed out
Connection timed out
Connection timed out
Connection timed out
Connection timed out
Connection timed out
Connection timed out
Connection timed out
Connection timed out
Connection timed out
Connection timed out
Connection timed out
Connection timed out
Connection timed out
Connection timed out
Connected to 192.168.0.105: time=118.02ms protocol=TCP port=5555
Connected to 192.168.0.105: time=140.02ms protocol=TCP port=5555
Connected to 192.168.0.105: time=57.01ms protocol=TCP port=5555
Connected to 192.168.0.105: time=77.51ms protocol=TCP port=5555
Connected to 192.168.0.105: time=97.01ms protocol=TCP port=5555
Connected to 192.168.0.105: time=122.02ms protocol=TCP port=5555
Connected to 192.168.0.105: time=135.52ms protocol=TCP port=5555
Connected to 192.168.0.105: time=52.01ms protocol=TCP port=5555
Connected to 192.168.0.105: time=72.51ms protocol=TCP port=5555
Connected to 192.168.0.105: time=92.51ms protocol=TCP port=5555
Connected to 192.168.0.105: time=105.51ms protocol=TCP port=5555
Connected to 192.168.0.105: time=5.50ms protocol=TCP port=5555
所以,它看起来像设备超时一些输入数据,启动之后接受,后来超时随机。亚行是系统应用程序,所以它应该遵循任何指导原则,并且可以免费使用相同的漏洞。
有谁知道如何解决这个问题并使Android设备能够快速响应传入连接?否则,任何需要传入流量的应用程序都将变得越来越不可靠。
'连接的time out often.'?哪个连接?服务器听着不是吗?请清除。 – greenapps
是的,服务器正在侦听,并且由于某种原因,某些传入连接超时(根本无法连接),即使Java正在“accept”方法调用中等待。 – Vitaliy
你不是在怪车路由器吗?试过其他设备? – greenapps