A CGI which use socket / datagrams?

David Bovill david at openpartnership.net
Sat Jul 29 09:52:36 EDT 2006


Yes the script is running as a simple CGI under Apache on an OSX
machine on the LAN. I firsted tested the script in Rev using a simple
button. The script is the same as below but with "on startUp" replaces
with "on mouseUP". There is another script in a local revolution stack
which listens for the datagram. This worked fine but not as a CGI. I
tried various combinations changeing port numbers and closing or not
closing sockets.

In fact I got a response sent to the socket listner... the problem is
that I then want to send a reply to the calling cgi so that it does
not just hang there waiting for a response - it seems that the
sendData line prevents the cgi returning anything?

#!/usr/local/bin/revolution

--> all handlers

on startUp
    -- put "OK" && cgi_ListGlobals() into someText
    put url "file:test_kml.txt" into kmlTemplate
    sendData kmlTemplate
    cgi_ReturnText "Sent data"
end startUp

on sendData someData
    put "cube.local:66666|datagram" into sendSocket
    open datagram socket to sendSocket
    write someData to socket sendSocket
    -- close socket sendSocket
end sendData

function cgi_ListGlobals
    # loop over all of the global variables, getting name and value
    repeat for each item i in the globals
        put i && "=" && value(i) & return after buffer
    end repeat
    -- put return & the defaultFolder after buffer
    return buffer
end cgi_ListGlobals

on cgi_ReturnText someText
    # write minimal set of HTTP headers to stdout

    put "Content-Type: text/plain" & cr
    put "Content-Length:" && the length of someText & cr & cr
    put someText
end cgi_ReturnText



More information about the use-livecode mailing list