Page 1 of 3 123 LastLast
Results 1 to 10 of 23

Thread: Comserver - should I have one connection open at all times?

  1. #1
    Join Date
    Jul 2001
    Location
    Risør - Norway
    Posts
    5,305

    Default Comserver - should I have one connection open at all times?

    I finally got comserver working, with one second waits between opening the connection, sending the command and closing the connection. But I wonder if the best policy is not to close that communication at all, just keep it open at all times, or to close it after each event. Any thoughts? It may be a problem if one computer has to be rebooted, right? So there should be a check to see if the line is open. With list open connection from the demo, maybe?
    Tor - managing director of the Cinema Inferno home theater and multi-zone sound system with Girder running the show in the back, NetRemote as the GUI and Media Center 17, PowerDVD and ZoomPlayer as playback software
    Hobsyssel mastiffs: http://www.hobsyssel.no

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

    Default

    I'd say you should keep it open. Check the error return from con:SendEvent() and try reopening the connection if that fails.
    --Rob

  3. #3
    Join Date
    Jul 2001
    Location
    Risør - Norway
    Posts
    5,305

    Default

    OK, error checking is something I've never tried before...

    Code:
    con,err = con:SendEvent('comtest',200,1,'a','b',nil,'d')
    if ( con == nil ) then
    con,err = comserv.NewConnection( '192.168.0.25', 20005, 'girder', CallBack);
    con,err = con:SendEvent('comtest',200,1,'a','b',nil,'d')
    else
    end
    Of course that's wrong, but I like to at least show that I'm trying to do something by myself... ops: The error I get is:
    Code:
    [string "D:\Vidcap G4.GML:\Comservertest\Comserverte..."]:12: attempt to index global `con' (a number value)
    stack traceback:
    	[string "D:\Vidcap G4.GML:\Comservertest\Comserverte..."]:12: in main chunk
    Tor - managing director of the Cinema Inferno home theater and multi-zone sound system with Girder running the show in the back, NetRemote as the GUI and Media Center 17, PowerDVD and ZoomPlayer as playback software
    Hobsyssel mastiffs: http://www.hobsyssel.no

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

    Default

    Well, you need to open the connection first.
    --Rob

  5. #5
    Join Date
    Jul 2001
    Location
    Risør - Norway
    Posts
    5,305

    Default

    Code:
    if con == nil then
    function CallBack(Param1, Param2, Param3, Param4, Param5)
    
      print("called back:")
      
      print(Param1)
      print(Param2)
      print(Param3)
      print(Param4)
      print(Param5)
      
    end
    con = comserv.NewConnection( '192.168.0.25', 20005, 'girder', CallBack);
    con = con:SendEvent('comtest',200,1,'a','b',nil,'d')
    else
    con = con:SendEvent('comtest',200,1,'a','b',nil,'d')
    end
    Code:
    [string "D:\Vidcap G4.GML:\Comservertest\Comserverte..."]:16: attempt to index global `con' (a number value)
    stack traceback:
    	[string "D:\Vidcap G4.GML:\Comservertest\Comserverte..."]:16: in main chunk
    Never said I was smart...
    Tor - managing director of the Cinema Inferno home theater and multi-zone sound system with Girder running the show in the back, NetRemote as the GUI and Media Center 17, PowerDVD and ZoomPlayer as playback software
    Hobsyssel mastiffs: http://www.hobsyssel.no

  6. #6
    Join Date
    Jul 2001
    Location
    Risør - Norway
    Posts
    5,305

    Default

    Another attempt, and this one seems to actually work:
    Code:
    if ( con == nil ) then
    function CallBack(Param1, Param2, Param3, Param4, Param5)
    
      print("called back:")
      
      print(Param1)
      print(Param2)
      print(Param3)
      print(Param4)
      print(Param5)
      
    end
    con,err = comserv.NewConnection( '192.168.0.11', 20005, 'girder', CallBack);
    win.Sleep (500)
    print('Trigger Event Ref ID: '..con:SendEvent('comtest',200,1,'a','b',nil,'d'))
    else
    print('Trigger Event Ref ID: '..con:SendEvent('comtest',200,1,'a','b',nil,'d'))
    win.Sleep (500)
    end
    Am I right? Is that sound?
    Tor - managing director of the Cinema Inferno home theater and multi-zone sound system with Girder running the show in the back, NetRemote as the GUI and Media Center 17, PowerDVD and ZoomPlayer as playback software
    Hobsyssel mastiffs: http://www.hobsyssel.no

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

    Default

    That's looking better, although I'm not sure I'd put the call definition inside the if statement.

    You really need to check the sequence and error returned from SendEvent()
    if you get an error then you want to drop the connection and try to re-establish it, possibly even caching any event strings until the connection has been remade.
    --Rob

  8. #8
    Join Date
    Jul 2001
    Location
    Risør - Norway
    Posts
    5,305

    Default

    OK, can we repeat that in english, please? :wink: Anyway, that callback function, is that really necessary for this stuff? I have another attempt here:
    Code:
    if ( con == nil ) then
    con,err = comserv.NewConnection( '192.168.0.25', 20005, 'girder', CallBack);
    win.Sleep (1000)
    con:SendEvent('comtest',200,1,'a','b',nil,'d')
    else
    win.Sleep (1000)
    con:SendEvent('comtest',200,1,'a','b',nil,'d')
    win.Sleep (1000)
    end
    Here I can get the "pingpong" started, where G4 1 sends a command to G4 2 with a multigroup that shows the OSD on 2 plus a command from 2 to fire the thing again on 1 and so on. Seems to work all right.

    The first time it takes a couple of seconds, from then on it flashes like crazy. I have it on 100 ms, with a wait command for 100 ms, and it can really be psychedelic if you look at a big red square flashing like that!
    Tor - managing director of the Cinema Inferno home theater and multi-zone sound system with Girder running the show in the back, NetRemote as the GUI and Media Center 17, PowerDVD and ZoomPlayer as playback software
    Hobsyssel mastiffs: http://www.hobsyssel.no

  9. #9
    Join Date
    Jul 2001
    Location
    Risør - Norway
    Posts
    5,305

    Default

    I just found a fatal flaw in my script. If one server is reset, the whole process stops. And the sender can't see that it's not getting anything through. Is that what error checking in SendEvent() would do?
    Tor - managing director of the Cinema Inferno home theater and multi-zone sound system with Girder running the show in the back, NetRemote as the GUI and Media Center 17, PowerDVD and ZoomPlayer as playback software
    Hobsyssel mastiffs: http://www.hobsyssel.no

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

    Default

    Yep, that's the whole point.

    Something like this :-

    Code:
    if not con then
        con,err = comserv.NewConnection( '192.168.0.25', 20005, 'girder');
        win.Sleep (1000)  -- not sure this is required
    end
    local seq, err = con:SendEvent('comtest',200,1,'a','b',nil,'d')
    if err then
        con:Close()
        con = nil
    end
    --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
  •