Jump to content

Pinging a server


Mr.Loki

Recommended Posts

Posted

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 ;)

  • Like 1

If I help you in a thread and you need further assistance, please don't PM me - use the thread you created instead. This way everyone on the forum can take advantage of it.

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?

If I help you in a thread and you need further assistance, please don't PM me - use the thread you created instead. This way everyone on the forum can take advantage of it.

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

If I help you in a thread and you need further assistance, please don't PM me - use the thread you created instead. This way everyone on the forum can take advantage of it.

Posted

Not sure, I've never used that module myself. Are you unable to make a resource for the 2nd server?

If I help you in a thread and you need further assistance, please don't PM me - use the thread you created instead. This way everyone on the forum can take advantage of it.

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

 

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