PDA

View Full Version : How do I check if a server is up/available in NR?



NeoMorph
July 21st, 2007, 11:22 PM
I want to do the following...

1. Check if my xbox in another room is on.
2. If it isn't show an icon of a dead xbox on my pocket pc.
3. If it is up show a icon of a live xbox.

I'd like to do it similar to a yahoo widget I modified.
I seem to remember seeing something like it in another persons CCF but I can't think straight enough to put a decent search query to find it again... I just can't figure out what to look for lol.


I've attached a screenshot of my widget so you can see what I mean.

emmee
July 22nd, 2007, 02:24 PM
There's a NR variable that you can use to see if the NR client is connected to MediaBridge:

MP.LinkActive: "1" = Connected to Media Bridge; "0" = Not Connected.

The default CCF uses it to display a popup frame when the link is not active.

NeoMorph
July 22nd, 2007, 04:35 PM
There's a NR variable that you can use to see if the NR client is connected to MediaBridge:

MP.LinkActive: "1" = Connected to Media Bridge; "0" = Not Connected.

The default CCF uses it to display a popup frame when the link is not active.

Mediabridge isn't running on the XBOX. And my one server isn't either. I need some way to ping them.

Rob H
July 23rd, 2007, 02:26 AM
It would be fairly straightforward to do this with Girder, but I can't think of an easy way to do this in NR itself.

Jlee
July 23rd, 2007, 06:53 AM
It would be fairly straightforward to do this with Girder, but I can't think of an easy way to do this in NR itself.
Yep, Girder.LinkActive does the trick and that's what I use.

NeoMorph
July 23rd, 2007, 07:04 AM
Yep, Girder.LinkActive does the trick and that's what I use.

I'm guessing it's not part of Girder 3.3... Can't find anything in the user manual about it.

I suppose I should think about upgrading to the latest version of Girder. :(

edit: The girder 3.3 test link doesn't work even in the connection setup test... and the servers and xbox's aren't running EITHER mediaplayer or girder. There's got to be a way to be able to do a ping function.... After all, NR is a networked app and ping is one of the basic networking functions.

Barf
July 23rd, 2007, 12:30 PM
Hi NeoMorph,

to my knowledge, there is not a "universal" solution, since the ping protocol does not seem to be implemented in the Lua libraries. Furthermore, there is nothing that requires an otherwise sane application to reject ping requests -- they are sometimes considered as a security problem.

Anyhow, assuming that your "server" is answering http-requests on port 80 -- these days almost all old tin boxes do -- write the following LUA function in your startup file:



function thing_isalive(thing)
socket.http.TIMEOUT = 1;
local result,errmess = http.request('http://' .. thing);
return result ~= nil;
end;

Then you define a button or frame with a state, the state selecting rule being a LUA call consisting of calling thing_isalive with argument the IP-name/address of your server (as LUA string).

If the server does not answer http requests, but listen on some other port, I leave it "as an excercise to the reader" to modify the code above. (See my previous posts on socket programming in LUA.)

Jlee
July 24th, 2007, 02:22 AM
I'm guessing it's not part of Girder 3.3... Can't find anything in the user manual about it.

I suppose I should think about upgrading to the latest version of Girder. :(

edit: The girder 3.3 test link doesn't work even in the connection setup test... and the servers and xbox's aren't running EITHER mediaplayer or girder. There's got to be a way to be able to do a ping function.... After all, NR is a networked app and ping is one of the basic networking functions.
I'm using Girder 3.3. Don;t take any notice of the test connection as that doesn't seem to work properly with 3.3. Girder.LinkActive does work however.

maxthebuilder
December 10th, 2007, 08:49 AM
Hello,
I am trying to do the server-check too (no MB or Girder on server).
Tried the code by Barf.. didn't work - NR gives an error message "attempt to index global 'http' (a nil value)"...
Any idea?
Thanks!
--max


Hi NeoMorph,
Anyhow, assuming that your "server" is answering http-requests on port 80 -- these days almost all old tin boxes do -- write the following LUA function in your startup file:



function thing_isalive(thing)
socket.http.TIMEOUT = 1;
local result,errmess = http.request('http://' .. thing);
return result ~= nil;
end;

Then you define a button or frame with a state, the state selecting rule being a LUA call consisting of calling thing_isalive with argument the IP-name/address of your server (as LUA string).

tmorten
December 10th, 2007, 09:26 AM
It looks like the socket library is being used, so I think you might need to add a "require"...


local socket = require( "socket" );

Best,
Tim

maxthebuilder
December 10th, 2007, 09:41 AM
Tim,
I did use
require( "socket" )
require( "socket.http" )
without "local" though.. Does it make a difference?
Thanks!


It looks like the socket library is being used, so I think you might need to add a "require"...


local socket = require( "socket" );

Best,
Tim

tmorten
December 10th, 2007, 03:50 PM
The local is just for scoping (to make it available only in the local function), so that shouldn't matter.

It doesn't look like "http" has been defined in the code fragment that was posted, so that's the problem.

I'm guessing they meant "socket.http.request".

Cheers,
Tim

maxthebuilder
December 10th, 2007, 04:21 PM
socket.http
took care of the error message..

Thanks Tim!

maxthebuilder
December 10th, 2007, 04:58 PM
Couldn't make this thing work..
I guess one needs a web server running for it to work.

Here's what I use and it works (reads some file on the server, in my case Z:\servercheckdummy.txt - if connected - True, not connected - False):

-- Pseudo ping
function thing_isalive(thing)
local result,errmess = io.open(thing);
return result ~= nil;
end;

Serverstatus = tostring(thing_isalive("Z:\servercheckdummy.txt"))
NetRemote.SetVariable('Serverstatus', Serverstatus)