2 sheets tagged with "network":
|
XMLRPC to call from Resolver One to a Python server NB this spreadsheet will only work in Resolver One version 1.4 or later. This spreadsheet and the accompanying script are based on one of the examples from the documentation for Python's XMLRPC library - see the "More information" link below. The Python script, when executed either using CPython or using IronPython with the Python 2.5 libraries installed, runs as an XMLRPC server that exposes one very simple function, is_even, which takes a number and returns whether or not that number is even. The spreadsheet uses some simple pre-constants user code to connect to this server, and then a column-level formula in column B (click on the column B header to see it) that calls the server to check the evenness of every number in column A. This is a really simple example of something very powerful - it shows how you can call external XMLRPC services from within your spreadsheets. |
|
Make a TCP request on every recalc, decoding JSON in the response to update worksheet In this example, Resolver acts as a TCP client, sending requests for data on every recalc. Recalcs have been set to automatically re-occur every second (note, this auto-recalc stops if you suspend recalcs using the toolbar button, Unzip the attached to provide the following three files: json-over-tcp.rsl - a Resolver document Open the .rsl document. Outgoing TCP messages are produced on every recalc, by the function These will currently give the following error: couldnt connect to server This is coming from the print in the request() function, The error is because nothing is listening to the port on which Resolver is asking for data. Open a command-line window, and cd to the directory containing these files. Enter the command: python test-server.py It should start a TCP server, and produce the message: listening on localhost:9999 Now, whenever a Resolver recalc occurs, the function 'request' sends a message, consisting merely of the word 'get', sent to localhost 9999. The responses, sent back by test-server.py, contain some JSON data, containing a list of (col, row, value) triples. The JSON response is received by Resolver in 'request()', and printed to the output pane: -------- Recalculation Started: 16:49:50 -------- This JSON is converted into Python data structures in the pre-formula user code, using the dirty hack: data = eval(json) # this works because json is valid Python The decoded data is then used by function 'display()' to display words and colors on the worksheet. If you click on the grid (ie. not on the code pane) then recalcs will Alternatively, requests like this could be put into button handlers instead of on every recalc. This would be arguably easier, since button handlers are magically able to persistantly update cell values, using the Formula property, |
