# How to send computing results?

32 views
Thanks again for all your help before.

I want to realise transport channel between WooDEM and my program on http server. I would like to send result of calculations (namely the coordinates of the figures at each time point) by POST request on my server and process them.

From documentation I don't understand clearly from which part (module, class or function...) I can send requests with coordinates. Can you help me solve my problem?

Thanks a lot!

answered Jun 1, 2017 by (46,530 points)
selected Jun 2, 2017

Hi Roman,

the easiest approach is to define python function which will do the POST request, and call it periodically from engines, something like this:

S.engines=woo.dem.DemField.minimalEngines(...)+[
woo.core.PyRunner(1000,"doPostData(S)") # run every 1000 steps
]

def doPostData(S):
# You need http://docs.python-requests.org/ package for this, easy to install through
# either APT (sudo apt install python3-requests) or pip (pip3 install requests)
import json, requests
# let's send all node's coordinates
# we encode the list of tuples as JSON (but can be anything the other side can accept)
# and put into a dictionary as "coords", so that other things can be added easily
# finito

I did not test the code, but this would be the idea. Of course, if you call it in every step, it will be very slow; if you need performance, an engine like this could be implemented in c++ and send out using some efficient protocol (like protobufs or boost::serialization). My guess is, though, that most time spent will be attributable to network latencies.

Another speedup option would be to obtain lock, start the request and let it continue in a separate thread (releasing the thread when done); the function would send data only if the previous request is done, thus not slowing down the computation. Many options, all depends on what exactly you need.

Cheers, Vaclav

commented Jun 2, 2017 by (250 points)

Thank you so much, Vaclav! I'll keep you informed.