Android http connection - multiple devices cannot connect the same server

妖精的绣舞 提交于 2019-12-01 05:51:59

问题


I really need help here...

I have a simple Android application that connects to my sever to fetch data over HTTPS.

Everything is working fine up until i connected to the same server from another device (iOS or Android). I am starting to get timeouts or connection refused or other errors depending on the library that I use (sometimes SSL handshake)

  1. I tried 2 android app on the same router - fails

  2. I tried Volley, Retrofit, plain http library - fails

  3. if one device is connected via cellular network and one on wifi, it is working fine. However, i have seen cases that it fails even using 2 devices connected to cellular network and not wifi.

  4. It is easy to reproduce. one app is working fine. as soon as i do an operation on the other device. the first app will not be able to connect.

  5. iOS app using the same api/server is working fine. no failures

  6. I ran wireshark on the android app during failure and received the following:

70 47.073286 10.0.0.1 10.0.0.138 ICMP 120 Destination unreachable (Port unreachable)

Seems like port issues. I am not sure anymore if this is a server issue or a client issue.. iOS app works fine. no issues. Only Android.

I tried:

System.setProperty("http.keepAlive", "false");

I tried setting an http header "connection :close" nothing works...

Any idea would be appreciated...


回答1:


Same problem here . When my ios device connect to allstar heroes or fun run application the android device cant connect anymore . I cant find s fix for that . My router is tp link dir 615 . Maybe the problem is frpm router .




回答2:


At the end of the day, it was server side issue. the IT guy gave me the following info: "incorrect flag on the tcp kernel settings" "Reuse connection" that is all I have for you. hope it can help someone else




回答3:


I had the same problem. The issue seemed to be when the app tried to access ports in TIME_CLOSE here is a great explanation how this happen, changing the tcp kernel to Reuse connection, might solve the problem since the server will try to re-use those connection in TIME_CLOSE again. but it must be a solution from the client side to avoid the connection to get stuck. in my case I was trying to create connection from multiples activities and i guess they, somehow, competed for opening and closing the connections, i solved the issue using a single activity to make the connection to the server.

hope this is useful to someone.




回答4:


Had exact the same issue and spent a lot of time investigating, nothing helped including "Reuse connection" flag, tried also to disable tcp_timestamp, tcp_tw_reuse, tcp_tw_recycle and enable vm safe mode for the app as suggested here:

  • https://github.com/square/okhttp/issues/903
  • https://github.com/square/okhttp/issues/1037
  • https://github.com/square/okhttp/issues/1518

but all in vein.

Further more, the very strange thing was that I had two different instances/servers which I made exactly the same in order to track down the issue and one server didn't have any issues.

So in the end:

Instance reboot solved problem with connections. (or just need to restart networking service)

(c) My server/instance admin



来源:https://stackoverflow.com/questions/28623779/android-http-connection-multiple-devices-cannot-connect-the-same-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!