mharj / minecraft-ping

Minecraft server ping
MIT License
18 stars 2 forks source link

Reduce ping timeout #4

Closed alex-r89 closed 2 years ago

alex-r89 commented 3 years ago

Hi there,

Sorry, this isn't really an issue, but would it be possible to reduce the timeout on the ping? 10 seconds seems to be quite a long time. Either a reduction or allow this to be configured?

My use case is to ping servers (up to 20) for a web page at build time, which delays significantly if just one of these servers happens to be offline.

This in fact, indirectly, does cause an issue because the serverless function provided by my host to build the page times out with just one server being offline.

A potential work around I thought of was to use this on the client, let the entire page load and then just fetch the server data on the client, however I cant use this on the client because I cant use the 'dns' package in the browser.

Thanks.

mharj commented 2 years ago

Added option for timeout (0.0.6 version)

On large server lists I would suggest that use event based communication with UI as then timeouts does not really matter. My current implementation is driven in fully async mode with each server having own setInterval those pings (I even change intervals as if server timeouts, then it's only checked once for 60 sec else every 2 sec) and when those ping response events are happening, then pushed via websocket to clients UI.

Anyway .. timeout is now configurable, happy hacking!

alex-r89 commented 2 years ago

Hi,

Thanks for adding this, and sorry for commenting on a closed issue - but what do you mean by "I would suggest that use event based communication with UI" ?

Are there any npm packages using event based communication? I cant seem to find any nor do I know what this means.

Thanks

mharj commented 2 years ago

@alex-r89 There is many ways to push events to UI, but I'm just using expressjs websocket where clients just connecting to websocket route. Basically then just let ping mc servers on own intervals and after promise is done just send JSON to all open websockets about servers updated status. Sadly I don't have any simple example to show as my current setup is very complex packet dispatcher setup which handle many different event packets in and out. https://sahara-lan.firebaseapp.com/ here is working UI setup, you can open developer view and check websocket messages how mc ping sends data to get idea.