Max Usanin
Max Usanin

Reputation: 2499

what a client connection can I use for the game client?

I am using http servlet on my server.

My game client uses the next http connection:

InetAddress inteAddress = InetAddress.getByName(server);
SocketAddress socketAddress = new InetSocketAddress(inteAddress, port);

// create a socket
socket = new Socket();

// this method will block no more than timeout ms.
int timeoutInMs = 10*1000;   // 10 seconds
socket.connect(socketAddress, timeoutInMs);

Time socket connection = 10 seconds... but I need to keep the connection

What a client connection can I use for the game client? (Looking for best practice)

Upvotes: 1

Views: 53

Answers (1)

mthmulders
mthmulders

Reputation: 9705

As soon as your socket connection is established, you can keep it around and reuse it as you see fit.

The value for the timeout parameter only has effect during establishment of the connection. If it's 10 seconds, as in your example, the implementation will try to establish a connection for 10 seconds (the method call is blocked during that time). If the implementation fails to establish a connection within those 10 seconds, it will fail.

Upvotes: 2

Related Questions