Comments (2)
Sorry for the late response.
In your while loop, you have already closed the client after the first iteration, since you are using it inside a try-witch-resources block. You cannot re-use the same instance after closing it.
The rule of thumb is to only instantiate the client once (as it can be expensive) and close it once you are done using it.
Moving the client reference out of your while loop should fix it.
@Test
public void check() throws InterruptedException {
int count = 1;
Server server = new Server();
server.setAddress("192.168.3.3:27005");
try (SourceQueryClient sourceQueryClient = getClient()) {
while (true) {
int finalCount = count;
final CountDownLatch latch = new CountDownLatch(1);
System.out.printf("[%d] Request\n", finalCount);
sourceQueryClient.getInfo(server.getInetAddress()).whenComplete((info, error) -> {
latch.countDown();
if (error != null) {
server.SetDownStatus();
return;
}
System.out.printf("[%d] Player count: %d\n", finalCount, info.getResult().getNumOfPlayers());
});
latch.await();
count++;
Thread.sleep(500);
}
} catch (CompletionException | IOException err) {
err.printStackTrace();
}
}
public SourceQueryClient getClient() {
if (sourceQueryClient == null) sourceQueryClient = new SourceQueryClient();
return sourceQueryClient;
}
More example:
- https://ribasco.github.io/async-gamequery-lib/examples/source_query_example.html
- https://github.com/ribasco/async-gamequery-lib/blob/master/examples/src/main/java/com/ibasco/agql/examples/SourceQueryExample.java
from async-gamequery-lib.
No further feedback. Closing..
from async-gamequery-lib.
Related Issues (20)
- Game Server Port should be read as unsigned Short HOT 1
- Add method for checking if the log service has already been started
- New Release for CVE-2022-42889 HOT 1
- Prompt me for connection timeout when I use this library HOT 4
- Compatibility with GraalVM Native Image HOT 3
- SourceQueryClient has a memory leak HOT 1
- Invalid packet type: 1 HOT 7
- Version 1.2.1 has dependencies with security vulnerabilities
- Cyrylic support HOT 1
- Remaining Bytes = 0 after reading 1-2-3 packets from 5 HOT 1
- bug: reading the rules of a V Rising server sometimes fails HOT 3
- Add new Http Option for web api key
- Add Server Port to SourceQueryInfoResponse HOT 3
- Map network protocol version in Source A2S_INFO decoder
- Add sourceTvProxy flag
- Use daemon threads for the default executor
- hi I use the ROCN library to link the game server and always prompt the link timeout HOT 8
- Rust RCON: Invalid packet type: 4 HOT 4
- Incompatibility with Spring Boot HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from async-gamequery-lib.