Closed ghost closed 10 years ago
initialize()
makes several requests to a server. Depending on the response time of an individual server this may vary from server to server. Additionally a server might respond faster or slower from time to time.
Generally, you might leverage better results when using multi-threading, but the times for an individual server might still vary a lot.
Ok, i am using threads for this (pool of 50 threads). But this not so fast as in standard serverbrowser by Steam or in game.
ExecutorService executor = Executors.newFixedThreadPool(50);
for (int i = 0; i < servers.size() - 1; i++) {
Runnable worker = new GetServersInfo(servers.get(i).getAddress().toString().replace("/", ""), servers.get(i).getPort(), "" + i);
executor.execute(worker);
}
executor.shutdown();
//while (!executor.isTerminated()) { }
System.out.println("Finished all threads");
public class GetServersInfo implements Runnable {
private String address;
private int port;
private String command;
public GetServersInfo(final String address_arg, int port_arg, String s) {
this.address = address_arg;
this.port = port_arg;
this.command = s;
}
@Override
public void run() {
System.out.println(Thread.currentThread().getName() + " Start. Command = " + command);
try {
GoldSrcServer temp_server = new GoldSrcServer(address, port);
temp_server.initialize();
} catch (SteamCondenserException e) {
//e.printStackTrace();
System.out.println("SteamCondenserException if initializing the socket fails");
} catch (TimeoutException e) {
//e.printStackTrace();
System.out.println("TimeoutException if too many timeouts occur while querying the server");
}
System.out.println(Thread.currentThread().getName() + " End.");
}
@Override
public String toString() {
return this.command;
}
}
Like said before initialize()
makes several requests. At least the request for a challenge number is not required if you just want to list the servers. So you might be better off with just using the following:
temp_server.updatePing();
temp_server.updateServerInfo();
Someone knows why the time initialize() server is not directly proportional to the increase of the number of respondents servers? 1 server: 0.100690964 s 2 servers: 4.701786192 s 3 servers: 4.859124065 s 4 servers: 9.422729783 s 5 servers: 14.101701261 s 10 servers: 15.83547205 - 23 s 20 servers: 15.836554095 - 71.335466586 s
Maybe i am made something wrong, or maybe need use multithreading?
I am use a code: