Results 1 to 9 of 9

Thread: Comserver: This really should be easier!

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

    Default Comserver: This really should be easier!

    Some of you guys know me, I'm no wiz at all with Lua. I like to call myself a power user, but I'm no coder. On the other hand I'm not totally stupid. Stupid, yes. But not totally! :roll: And going from a very simple Internet Event Server/Client to something that really confuses me seems like it may be a move that may really scare newbies. I'm too stubborn (or stupid?) to be scared, I bang my head into the brick wall until it breaks. But it seems to me that it should be possible to simply run something like this, without any extra code at all:

    Code:
    comserver(192.168.0.25,20005,"eventstring","payload1")

    That's something everybody can understand. The "open connection, check connection, send, close connection, pull your hair out because you can't get a connection" dance is a bit to complicated in my opinion. I should think this culd be done with some kind of a Lua file installed in the luascript directory or some Lua code created automatically. Or can't it? Anybody up for the task? (He said, hopefully...)
    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
    Jul 2001
    Location
    Risør - Norway
    Posts
    5,321

    Default

    OK, maybe it should be even easier. What about a function that implements this code:

    Code:
    function ComServer
    if( con == nil ) then 
    con,err = comserv.NewConnection( '192.168.0.25', 20005, 'girder',nil); 
    win.Sleep (1000) 
    con:SendEvent(param1,200,1,'a','b',nil,'d') 
    else 
    win.Sleep (1000) 
    con:SendEvent(param1,200,1,'a','b',nil,'d') 
    win.Sleep (1000) 
    end
    end
    So this is all the code to send to the computer with that IP:
    Code:
    ComServer("test")
    I know that's doable, but for me? ops:

    I get this:
    Code:
    [string "Scripting"]:2: `(' expected near `if'
    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

  3. #3
    Join Date
    Sep 2003
    Location
    reading / bournemouth UK
    Posts
    1,106

    Default

    Code:
    function ComServer()
    if( con == nil ) then
    con,err = comserv.NewConnection( '192.168.0.25', 20005, 'girder',nil);
    win.Sleep (1000)
    con:SendEvent(param1,200,1,'a','b',nil,'d')
    else
    win.Sleep (1000)
    con:SendEvent(param1,200,1,'a','b',nil,'d')
    win.Sleep (1000)
    end
    end
    a function must be declared with parameters even if there are 0 of them

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

    Default

    Then that works, thanks! But when I try
    Code:
    ComServer("comtest")
    I get
    Code:
    [string "D:\Vidcap G4.GML:\Comservertest\Scripting"]:8: bad argument #1 to `SendEvent' (string expected, got nil)
    stack traceback:
    	[C]: in function `SendEvent'
    	[string "D:\Vidcap G4.GML:\Comservertest\Scripting"]:8: in function `ComServer'
    	[string "D:\Vidcap G4.GML:\Comservertest\Comserverte..."]:1: 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

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

    Default

    Hang on, I need to change something. It turns out that if one of the computers has a reset, it all falls. Which is why it needs to use this error checking (from Rob):
    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
    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
    Sep 2003
    Location
    reading / bournemouth UK
    Posts
    1,106

    Default

    if you want to pass the function a string then you will need to declare it to have a string as a parameter:
    Code:
    function ComServer(msg)
    if( con == nil ) then
    con,err = comserv.NewConnection( '192.168.0.25', 20005, 'girder',nil);
    win.Sleep (1000)
    con:SendEvent(msg,200,1,'a','b',nil,'d')
    else
    win.Sleep (1000)
    con:SendEvent(msg,200,1,'a','b',nil,'d')
    win.Sleep (1000)
    end
    end

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

    Default

    OK, so with the new error checking that should be something like:
    Code:
    function ComServer(msg)
    if not con then 
        con,err = comserv.NewConnection( '192.168.0.25', 20005, 'girder'); 
        win.Sleep (100)
    	end 
    local seq, err = con:SendEvent(msg,200,1,'a','b',nil,'d') 
    	if err then 
        con:Close() 
        con,err = comserv.NewConnection( '192.168.0.25', 20005, 'girder'); 
        win.Sleep (100)
    local seq, err = con:SendEvent(msg,200,1,'a','b',nil,'d') 
    end
    end
    I will try 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

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

    Default

    This time I don't get an error, but nothing happens. I'm using the same code for the action - ComServer = ("comtest")
    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,321

    Default

    Got it working.
    Code:
    Server = ComServer("comtest")
    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

Posting Permissions

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