Mr.Loki Posted October 16, 2016 Share Posted October 16, 2016 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
Dealman Posted October 16, 2016 Share Posted October 16, 2016 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 1 Link to comment
Mr.Loki Posted October 16, 2016 Author Share Posted October 16, 2016 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
Dealman Posted October 16, 2016 Share Posted October 16, 2016 Well yeah, how else would you communicate with it? The server won't magically know what it is you want it to do It returns true if the function was called, otherwise false. So if false, you can assume the server is offline? Link to comment
Mr.Loki Posted October 16, 2016 Author Share Posted October 16, 2016 Damn.... Welp thanks m8 Link to comment
Dealman Posted October 17, 2016 Share Posted October 17, 2016 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. Link to comment
Mr.Loki Posted October 17, 2016 Author Share Posted October 17, 2016 Do you know any other way? would ml_sockets work? Link to comment
Dealman Posted October 18, 2016 Share Posted October 18, 2016 Not sure, I've never used that module myself. Are you unable to make a resource for the 2nd server? Link to comment
Mr.Loki Posted October 18, 2016 Author Share Posted October 18, 2016 I am able to but I want it to be able add and removing servers from the script with ease. Link to comment
Captain Cody Posted October 18, 2016 Share Posted October 18, 2016 (edited) You could probably find a way to pull the data that is being sent to game-state.com and use it to ping said server. Edited October 18, 2016 by CodyL Link to comment
Mr.Loki Posted October 19, 2016 Author Share Posted October 19, 2016 That would require adding the server to game-state.... but its 1 way Link to comment
Captain Cody Posted October 19, 2016 Share Posted October 19, 2016 Well there's only so much ways that you can get details from another server. 1 Link to comment
Mr.Loki Posted October 19, 2016 Author Share Posted October 19, 2016 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. Link to comment
LoveFist Posted October 19, 2016 Share Posted October 19, 2016 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 1 Link to comment
Mr.Loki Posted October 19, 2016 Author Share Posted October 19, 2016 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
pa3ck Posted October 19, 2016 Share Posted October 19, 2016 Which port are you trying to ping? HTTP or server port? 1 Link to comment
Mr.Loki Posted October 20, 2016 Author Share Posted October 20, 2016 (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 October 20, 2016 by loki2143 update Link to comment
pa3ck Posted October 20, 2016 Share Posted October 20, 2016 You obviously need the http port to send http data you're welcome 1 Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now