Jump to content

Pinging a server


Mr.Loki

Recommended Posts

Posted

Is there anyway to ping another serer from a server?

I've been trying to find a way for a while now but no luck with using the call/FetchRemote functions and APIs.

I'm creating a redirect script and want to get the redirected server's online/offline status before connecting the player.

Posted
7 hours ago, Dealman said:

You should be able to do this fairly easily with callRemote. You can specify a resource and a function name to execute. Go wild with it ;)

Would I need to set it up on the server that I'm trying to get a connection from?

Because I just want to check if the server is online.

Posted

Well yeah, how else would you communicate with it? The server won't magically know what it is you want it to do :P

It returns true if the function was called, otherwise false. So if false, you can assume the server is offline?

Posted

That's just an easy way of doing it, it's not very reliable as it may fail and return false for other reasons. To make sure it's reliable you'll want to make use of a callback function. :)

Posted
1 hour ago, CodyL said:

Well there's only so much ways that you can get details from another server.

Well i don't really need details all i want to know is if a server is online or not.

Posted

I think you can use callRemote even without adding to remote server additional resources. Just make a call with some fake data and then check error code in callbackResponse.

If server offline then you will get some timeout error code.

If server online then it will be some "access denied" error or something different.

 

More info about error codes:

https://wiki.multitheftauto.com/wiki/Template:Error_codes_for_callRemote_and_fetchRemote

 

  • Like 1
Posted
16 hours ago, LoveFist said:

I think you can use callRemote even without adding to remote server additional resources. Just make a call with some fake data and then check error code in callbackResponse.

Nope still did not work.

I tried so many ways but all i got was operation Timed out(28) no matter if the server is online of offline.

 

addEvent( "onDxRedirect",true )
addEventHandler( "onDxRedirect", root, function (ip,port,who)
   --redirectPlayer( source, ip, port )
   local msg = "#FF0000[Redirect] #FFFFFF"..source.name.." connected to "..who.." server."
   triggerClientEvent( "onDisplayTopNotification", root, msg )

	local address = ip..":"..port
	outputDebugString( address )
	local called = callRemote ( tostring(address), 2, getResourceName(getThisResource()), "imPingingYou", finishedCallback, source.name,getServerName())
	outputDebugString(tostring(called))
end )

function finishedCallback( responseData, errno )
   triggerClientEvent( "onDisplayTopNotification", root, responseData.." with ID #"..errno,600000 )
end

 

Posted (edited)
3 hours ago, pa3ck said:

Which port are you trying to ping? HTTP or server port?

server ports

Edit: ooh you have to use the HTTP ports lol

It works now i get a 401 Unauthorized as @LoveFist mentioned

Thanks for your help guys ._.

Edited by loki2143
update

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...