Send and execute a file on a networked computer

Some lengthy, sequential programs can be broken into stages that could be parallel processed on several network machines, with one machine acting as controller.

As a starter, I checked that I can send to a client machine a control file, holding the name of an executable LB token, any in or out files it is to use, and a flag for whether it is to execute a new program; is already running one; or has completed the task. I also send it the tkn file. This can be direct file saving across the network, SSH, or across the 'net. The client has to be already running a timer loop to look for the local existence of such a control file.

I chose for convenience to run a text editor, which saves the control file for me across the network to a client computer.

updated by

The client computer checks the control file regularly under timer control, and for test purposes shows a window displaying what control state it is in. This gives an easy way to debug, and more importantly a way to shut down the timer polling loop.

As an example, the requested token file pops up a screen as evidence it was called, and removes itself after an interval. It alters the conrol flag to show it has been first called, then that it has finished.

and state of handshake file

Intended use

As an example, I can split on one computer a BMP file into the preamble, and two halves. The two halves, holding half the pixel data each, can be inverted pixel by pixel, in two separate computers. The original program gets back the info that both have executed, and reassembles the result. Potentially all computers I have access to on my network could share the load.

It's a crazy example of course. Paint programs like GIMP do it in a fraction of a second in optimised compiled code... But I needed an example that takes minutes or more in native LB code and is essentially a parallel problem.

This bit of coding at present processes the two halves consecutively on one computer, but it should be easy to merge the code with the code given here. However I haven't really thought through the potential collisions on the control file in such cases. The machines only briefly open, modify and re-save it. BUT.. it's been fun to get this far...

A typical requested LB program for the client to run, saved as a tkn file.

    '   Open the control file. If fourth word is '0' re-save with a '1' to indicate task started.
    '       Start task.


    open  "taskSpec.jhf" for input as #inF
        content$ =input$( #inF, lof( #inF))
    close #inF

    content$ =left$( content$, len( content$) -1) +"1"

    open  "taskSpec.jhf" for output as #oF
        #oF content$;       '   write a '1' to end of 'taskSpec.jhf'.
    close #oF

    statictext "", 20, 20, 220, 220

    open "Opened at " +time$() for window as #w
        #w    "trapclose [quit]" "!font arial bold 24" "I will close after 10s if you don't do it yourself!"

        'calldll #kernel32, "Sleep", 20000 as ulong, null as void

        now =time$( "seconds")

        if time$( "seconds") -now <10 then scan: goto [l1]

        '   Task finished- write control file with a '2' to show this.
        content$ =left$( content$, len( content$) -1) +"2"
        open  "taskSpec.jhf" for output as #oF
            #oF content$;      'write a '2' to end of 'taskSpec.jhf'.
        close #oF

        close #w

Typical LB polling code for the client to continually execute.

    '   Program sets a timer which every 2 second checks for a task-specifying file
    '       at a particular network location specific to this computer.

    '   If this file exists, it holds the name of an LB tkn file to execute..
    '       and of an In-file and Out-file to process, and a flag 'taskCompleted'.
    '   e.g. "invertBytes.exe,infile.jhf,outfile.jhf,0" means use 'invertBytes.exe' to process
    '       file 'infile.jhf', put result in 'outfile.jhf' and save modified 'taskSpec.jhf'
    '       as "invertBytes.exe,infile.jhf,outfile.jhf,1".

    'open "taskSpec.jhf" for output as #oF  '
    '    #oF "task.tkn,infile.jhf,outfile.jhf,0";
    'close #oF

    '   Save taskSpec.jhf holding 'invertBytes.exe,infile.jhf,outfile.jhf,1' before running.
    '           0 ==request-to-process      1 ==task running           2 ==task completed.

    'nomainwin  '   otherwise hard to turn off background controller /timer.
    print "Close me to stop the polling loop.."
    timer 100, [checkFile]

    timer 0
    open "taskSpec.jhf" for input as #in
        content$ =input$( #in, lof( #in))
    close #in

    program$ =word$( content$, 1, ",")
    inFile$  =word$( content$, 2, ",")
    outFile$ =word$( content$, 3, ",")
    state$   =word$( content$, 4, ",")

    print state$;  '   debugging- progress indicator.

    select case state$
        case "2"
        '    task was called and has completed.
        case "1"
        '    called task is still running..
        case "0"
            run program$    '   which will set flag to '2' when it finishes.
    end select

    'timer 1000, [o2]
    timer 2000, [checkFile]