Always in JWrapper we aren't trying to bring you bog standard code you could find anywhere on the internet with our APIs, instead we try to give you utilities we've found helpful from decades of experience in Java programming. Utility APIs you may not even have realised you needed until you hit on some difficult to track down bug or weird behaviour.
The first of our APIs - JWSockets - allows you to do something which the standard APIs won't let you - track and debug all socket creation and disconnections within the JVM. If you're unsure about how your URL queries are being handled, or you're writing a game and you want to be sure you aren't making any mistakes, JWSockets gives you a bunch of useful functions to see whats happening.
The starting point is to set up JWSockets to intercept all socket activity:
JWSockets jwsocks = JWSockets.interceptSockets();
From there we can have it print all socket activity to the console:
Or we can have it retain a list of all live and closed sockets:
then get the lists, or the count of sockets in each state:
or even add a listener to get notified whenever a socket is opened or closed in the JVM:
The second API we've added is just the beginning of a new set of functions - JWNet. Currently this has just one function which sets the HTTP agent for all HTTP queries in the entire JVM.
Again, if you've tried to do this before you may have found pretty simple code which appears to set the HTTP agent for your queries like this:
But unfortunately what you might have missed is that although this does alter your HTTP agent string, it also appends 'Java' on the end. If you want it to pick up and use the exact HTTP agent you specify throughout the JVM, you can use JWNet.