0

good day stackoverflow! im not sure if any of you has tried this but basically i want to accomplish something like this: - a python program continuously sends data to my website - using that data computations will be made and images on the website are animate

so my questions are: 1. what method should i use to communicate python to the website? the easier and simpler the better (tried reading up on django and my nose bled) 2. is javascript the best way to move my images? or is flash better? 3. if flash is better, is it possible to use the input from python and pass it to flash?

user571099
  • 1,491
  • 6
  • 24
  • 42

2 Answers2

0

Images are not shown "on your website", they are shown "in your users' browsers".

The browser needs to request the animation information from your website, which needs to request it from (wherever it comes from). Ideally, the website will cache the data so that 20 browser requests result in just one website request.

  • How close to realtime is this information?
  • Where does it come from? Is it a service you can run on the webserver?
  • How often does the browser need to be updated?

You should look for information on AJAX (letting the browser make asynchronous requests from the website).

Hugh Bothwell
  • 55,315
  • 8
  • 84
  • 99
  • hello sir good morning! (1 , 3) data is sent every 1 second or so and if possible i want the updating to occur at the same time too (2) the python data comes from the same computer where i run the webserver – user571099 Feb 12 '11 at 23:11
0

There are basically 2 ways to do it.

  • Pooling - To put it simply it comes down to browser asking server "Do you have new data for me?" all the time. You can do that with Ajax. All mayor JavaScript libraries have easy to use Ajax functions.
  • Realtime - There are 2 ways to do this using JavaScript. Comet approach which usually means long pooling (you request a page from webserver and instead of sending it and closing the connection the server keeps sending data over time and never closes the connection). It's a bit nasty but works. The other way is using HTML5 API WebSockets, which opens a real TCP connection between browser and the server over which you can send your data.

Yes you can use flash, it has something similar to WebSockets. I think it might be even more powerful, but don't quote me on that. But then you'd have to learn Flash and probably make the image/animation in Flash.

Which one to use?

Web before HTML5 wasn't really intended to have realtime connections so all the approaches before HTML5 are more or less hacks, sometimes annoying to deal with and most likely will come with performance hit.

I'd say WebSockets is the way to go if you're just playing around. You'll need a modern browser which supports them though. If you need to support older browsers you'll have to use the other methods.

Flash works, but it requires plugin and most likely won't work on mobile devices. It's also a new language which you need to learn/support. Some people might have it blocked.

Python

If you chose one of the mentioned ways of doing it just Google it adding python keyword. There are quite a lot libraries out there for Python. Same with examples.

The most easiest to implement is probably Ajax pooling since you're just requesting a webpage. Just grab a simple python web framework like Bottle and you'll be ready in no time.

Comet is quite easy as well, but there might be some problems with keeping the connection open for long time and also when you have multiple such connections. You should grab one of the Comet implementations instead of trying to work this out yourself. Take a look at this - Python Comet Server

WebSockets and Flash will require you to write a separate server/script in python which serves the data. There are some available online where you just plug in your logic.

Community
  • 1
  • 1
Maiku Mori
  • 7,419
  • 2
  • 40
  • 52