Jump to content

Pinging a server


Mr.Loki

Recommended Posts

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.

Link to comment
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.

Link to comment

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
Link to comment
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

 

Link to comment

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...