Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java sockets (Android to Java server)

Tags:

java

sockets

I have a java program which runs as a server accepting connections, and I connect Android clients to it. Clients are connected for a long time to their sockets.

1) How many clients can I server concurrently have (in practice - im not talking about the number of ports now) on an average machine with 3 Gb RAM?

2) If the phone uses 3G for the connection, is it possible that the socket is broken? If it is, how do I recover it or should it be done from the client side? Or is it done automatically? Does it happen often?

like image 746
Artem Moskalev Avatar asked Oct 03 '22 17:10

Artem Moskalev


1 Answers

1) Depends on the what the server does for the clients. If the server just accepts the connection and does nothing more it can probably serve tens of thousands of clients. If the server does something that requires CPU, memory or I/O it can serve fewer clients.

2) Yes, TCP connections can break, even over wired networks. If the link comes back the socket connection is not broken; TCP handles the retransmission of lost data. The problem is, what happens if the link doesn't come back? If you use SO_KEEPALIVE the connection will be closed eventually, but since the default timeout is 2 hours applications sensitive to this issue implement their own timeout mechanisms.

like image 61
Joni Avatar answered Oct 07 '22 19:10

Joni