Results 1 to 9 of 9

Thread: what is the best way to detect NR disconnect ?

  1. #1
    Join Date
    Jan 2004
    Location
    The Netherlands
    Posts
    2,140

    Default what is the best way to detect NR disconnect ?

    I have :
    * PC A with G5,
    * PC B with JRMC,zoomplayer etc. (also has G5 installed and connected via G2G to PC A)
    * several NR clients

    from PC A, I want to switch on PC B (by sending magic packet) as soon as any NR connects to PC A...
    and I want to switch PC B to standby (via G2G), when there are no more NR clients connected to the PC A (always on).

    so I need an event that gets called when any NR client connects and disconnects and then I need a way to see the number of active NR clients ?

    what is the best way to do this ?

    I assume that I need to connect to these events:

    Time Date Source Details Payloads
    18:25:26:859 5/13/2007 Communication Server New Client Connection 192.168.1.33 3385
    ....
    ...
    18:25:59:777 5/13/2007 Communication Server Close Connection 192.168.1.33 3385
    18:25:59:737 5/13/2007 Communication Server Close Connection

    although I'm not sure why I see Close Connection twice ?

    Marcel
    Last edited by mhwlng; May 13th, 2007 at 11:27 AM.

  2. #2
    Join Date
    Jan 2004
    Location
    The Netherlands
    Posts
    2,140

    Default

    never mind, I figured it out

    this gives me the number of active clients :

    Code:
     
    local cnt = 0;
    for _, client in pairs(NetRemote.GetConnectedClientList()) do 
      if (client.Connected==true) then
        cnt=cnt+1;
      end
    end
    print (cnt);

    although I'm not sure why I see Close Connection twice ?
    only one of the two log entries is the event, the other one is a log message....

    Marcel
    Last edited by mhwlng; May 13th, 2007 at 01:40 PM.

  3. #3
    Join Date
    Jan 2004
    Location
    The Netherlands
    Posts
    2,140

    Default

    I have some strange results :

    these are actually G2G connections :

    PC 1 (192.168.1.62)

    Time Date Source Details Payloads
    09:56:05:695 5/16/2007 NetRemote Connection from 192.168.1.64:20005
    09:56:05:695 5/16/2007 Communication Server Outgoing Connection Authenticated
    09:56:05:554 5/16/2007 Communication Server New Client Connection 192.168.1.64 20005

    PC 2 (192.168.1.64)

    Time Date Source Details Payloads
    09:57:07:718 5/16/2007 NetRemote Connection from 192.168.1.62:4867
    09:57:07:703 5/16/2007 Communication Server New Client Connection 192.168.1.62 4867
    09:57:07:703 5/16/2007 Communication Server Connection Authenticated 192.168.1.62 GIRDER

    08:50:50:203 5/16/2007 Communication Server Existing Client GIRDER tabletpc 192.168.1.62 20005
    08:50:50:203 5/16/2007 Communication Server: Servers Server (GIRDER): tabletpc, @ 192.168.1.62:20005
    08:50:50:171 5/16/2007 Communication Server Existing Client GIRDER server 192.168.1.64 20005
    08:50:50:171 5/16/2007 Communication Server Existing Client MediaBridge server 192.168.1.64 20003
    08:50:50:171 5/16/2007 Communication Server: Servers Server (GIRDER): server, @ 192.168.1.64:20005
    08:50:50:171 5/16/2007 Communication Server: Servers Server (MediaBridge): server, @ 192.168.1.64:20003


    so above method doesn't work properly as G2G connections are sometimes seen as active NetRemote connections...

    note that this doesn't always happen.

    if I now stop/start G5 on 192.168.1.64, I see this on 192.168.1.62 :

    Time Date Source Details Payloads
    10:12:46:111 5/16/2007 Communication Server: Servers Server (GIRDER): tabletpc, @ 192.168.1.62:20005
    10:12:46:111 5/16/2007 Communication Server: Servers Server (GIRDER): server, @ 192.168.1.64:20005
    10:12:46:111 5/16/2007 Communication Server: Servers Server (MediaBridge): dev, @ 192.168.1.33:20003
    10:12:46:111 5/16/2007 Communication Server: Servers Server (MediaBridge): server, @ 192.168.1.64:20003
    10:12:46:001 5/16/2007 Communication Server Existing Client GIRDER tabletpc 192.168.1.62 20005
    10:12:46:001 5/16/2007 Communication Server Existing Client GIRDER server 192.168.1.64 20005
    10:12:45:991 5/16/2007 Communication Server Existing Client MediaBridge dev 192.168.1.33 20003
    10:12:45:981 5/16/2007 Communication Server Existing Client MediaBridge server 192.168.1.64 20003
    10:12:43:581 5/16/2007 Communication Server Existing Client GIRDER tabletpc 192.168.1.62 20005
    10:12:43:561 5/16/2007 Communication Server Existing Client GIRDER server 192.168.1.64 20005
    10:12:43:561 5/16/2007 Communication Server Existing Client MediaBridge dev 192.168.1.33 20003
    10:12:43:621 5/16/2007 Communication Server: Servers Server (GIRDER): tabletpc, @ 192.168.1.62:20005
    10:12:43:621 5/16/2007 Communication Server: Servers Server (GIRDER): server, @ 192.168.1.64:20005
    10:12:43:621 5/16/2007 Communication Server: Servers Server (MediaBridge): dev, @ 192.168.1.33:20003
    10:12:43:621 5/16/2007 Communication Server: Servers Server (MediaBridge): server, @ 192.168.1.64:20003
    10:12:43:431 5/16/2007 Communication Server Existing Client MediaBridge server 192.168.1.64 20003

    now, I don't see an NR connection (which is correct) ???

    Marcel
    Last edited by mhwlng; May 16th, 2007 at 03:19 AM.

  4. #4
    Join Date
    Jan 2004
    Location
    The Netherlands
    Posts
    2,140

    Default

    some more info on this,

    the G2G-connecting-as-NetRemote seems to happen after I stop a real NR pc (192.168.1.35) ????


    Time Date Source Details Payloads
    10:40:02:945 5/16/2007 NetRemote Connection from 192.168.1.64:20005
    10:40:02:895 5/16/2007 Communication Server New Client Connection 192.168.1.64 20005
    10:40:02:814 5/16/2007 Communication Server Outgoing Connection Authenticated

    10:39:02:437 5/16/2007 NetRemote Exiting feedback thread for 192.168.1.35
    10:39:02:437 5/16/2007 NetRemote Closing client for 192.168.1.35
    10:39:02:437 5/16/2007 NetRemote Unregistering NetRemote client 192.168.1.35:3197
    10:39:02:437 5/16/2007 NetRemote Connection closing 192.168.1.35:3197
    10:39:02:227 5/16/2007 Communication Server Close Connection 192.168.1.35 3197
    10:39:02:257 5/16/2007 Communication Server Close Connection

    I think this G2G connection does not show up in
    NetRemote.GetConnectedClientList()



    and here I switch the 192.168.1.64 G5 pc to standby, then this is what I see on 192.168.1.62

    it activates a false netremote connection while the G5 pc is shutting down and immediately closes it again ???

    Time Date Source Details Payloads
    10:55:47:602 5/16/2007 Girder to Girder ClientOffline SERVER 192.168.1.64
    10:55:47:502 5/16/2007 Communication Server Close Connection 192.168.1.64 20005
    10:55:47:482 5/16/2007 Communication Server New Client Connection 192.168.1.64 20005
    10:55:47:522 5/16/2007 NetRemote Connection closing 192.168.1.64:20005
    10:55:47:522 5/16/2007 Communication Server Close Connection
    10:55:47:522 5/16/2007 NetRemote Connection from 192.168.1.64:20005
    10:55:47:522 5/16/2007 Communication Server Outgoing Connection Authenticated


    Marcel
    Last edited by mhwlng; May 16th, 2007 at 04:06 AM.

  5. #5
    Join Date
    May 2004
    Location
    Cardigan, UK
    Posts
    9,278

    Default

    That's weird, sounds as though the message is being logged prematurely, ie before it has established that it's a real NetRemote client. If it's a real NR connection you should see an 'Adding client' message as well. I should probably remove the first message as it is clearly misleading.

    BTW you should be able to use NetRemote.RegisterConnectCallback and NetRemote.RegisterDisconnectCallback to track real, verified NR client connections and disconnections. The callback function takes the actual client as a parameter.

    Thanks for asking about this actually, I'd quite forgotten about it and happened to need it myself today
    Last edited by Rob H; May 16th, 2007 at 05:31 AM.
    --Rob

  6. #6
    Join Date
    Jan 2004
    Location
    The Netherlands
    Posts
    2,140

    Default

    you should be able to use NetRemote.RegisterConnectCallback and NetRemote.RegisterDisconnectCallback
    Thanks Rob,

    That works ok...

    p.s. I 've also added 1 minute timer to the standby mechanism in RegisterDisconnectCallback. So that my JRMC pc doesn't switch off, if there was only a WIFI comms error causing a short disconnect...

    Marcel

  7. #7
    Join Date
    May 2004
    Location
    Cardigan, UK
    Posts
    9,278

    Default

    By the way, you should probably check client.connectionValid in your connect callback to be on the safe side.
    --Rob

  8. #8
    Join Date
    Jan 2004
    Location
    The Netherlands
    Posts
    2,140

    Default

    well... I have to check for any client, not just the one causing the callback..
    so I use GetConnectedClientList :

    Code:
     
    Marcel = Marcel or {}
    Marcel.NetRemote = Marcel.NetRemote or {}
    Marcel.NetRemote.Interval = 60000;
    Marcel.NetRemote.NetRemoteTimer = nil
     
    function Marcel.NetRemote.clientconnect (client)
      if (Marcel.NetRemote.NetRemoteTimer ~= nil) then
        Marcel.NetRemote.NetRemoteTimer:Destroy();
        Marcel.NetRemote.NetRemoteTimer = nil
      end
      gir.LogMessage ("Marcel.NetRemote","Wake Up Server",0)
      ret,err =win.WakeOverLan("192.168.1.255", "00:19:DB:29:9E:AA")
    end
     
    function Marcel.NetRemote.TimerUpdate()
      local cnt = 0;
      for _, client in pairs(NetRemote.GetConnectedClientList()) do
        if (client.Connected==true) then
          gir.LogMessage ("Marcel.NetRemote","still connected "..client.Host,0)
          cnt=cnt+1;
        end
      end
      if (cnt==0) then
        gir.LogMessage ("Marcel.NetRemote","Stand By Server",0)
        g2g.SendEvent("G2GSTANDBY",nil,nil,"");
      end
    end
     
    function Marcel.NetRemote.clientdisconnect (client)
      if (Marcel.NetRemote.NetRemoteTimer ~= nil) then
        Marcel.NetRemote.NetRemoteTimer:Destroy();
        Marcel.NetRemote.NetRemoteTimer = nil
      end
      Marcel.NetRemote.NetRemoteTimer = gir.CreateTimer (nil,function (...)
                                                  return Marcel.NetRemote.TimerUpdate (unpack (arg))
                                                end,nil,false)
      Marcel.NetRemote.NetRemoteTimer:Arm (Marcel.NetRemote.Interval)
    end
     
    NetRemote.RegisterConnectCallback(function (...)  Marcel.NetRemote.clientconnect(unpack(arg)) end);
     
    NetRemote.RegisterDisconnectCallback (function (...)  Marcel.NetRemote.clientdisconnect(unpack(arg)) end);
    Marcel

  9. #9
    Join Date
    May 2004
    Location
    Cardigan, UK
    Posts
    9,278

    Default

    Right. You could also use NetRemote.EnumerateClients passing in a function to call for each client. See the implementation of GetConnectedClientList for the usage.
    --Rob

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •