python daemon + interprocess communication + web server - python

The situation:
I have a python script to connect/send signals to serial connected arduino's. I wanted to know the best way to implement a web server, so that i can query the status of the arduinos. I want that both the "web server" part and serial connection runs on the same script. Is it possible, or do i have to break it into a daemon and a server part?
Thanks, any comments are the most welcomed.

Have WAMP server. It is the easiest and quickest way. The web server will support php, python , http etc.
If you are using Linux , the easiest tool for serial communication is php.
But in windows php cannot read data from serial communication. Hence use python / perl etc.
Thanks

For those wondering what I have opted for; I have decoupled the two part:
The Arduino daemon
I am using Python with a micro web framework called [Bottle][1] which handles the API calls and I have used PySerial to communicate with the Arduino's.
The web server
The canonical Apache and PHP; are used to make API calls to the Arduino daemon.

Related

Socket communication with Django

Is it possible to use Django for communication with some kind of server process? For example on my Django website I want to have form where I input connection details (host and port) and after connection I want to send some request or events to other server process (some simple action like slider moving or clicking a button). Can I use python socket programming for this or is there some easier way?
You can use with django any python packages as with any "normal" python program. If you have a module, that communicate with your server, you can use this, if not, you have to write one on your own possibly with socket programming.

How can a Django application interact with other python programs running on the same server?

We have various python applications of varying sizes in our arsenal that provide specific services. What I intend to do is create a website using Django that is able to interact with these other applications in order to provide a web interface to access some features of these external applications and monitor their response. I can handle the Django side well, thanks to their awesome documentation, but I'm somewhat lost when it comes to the big picture. How would one go about establishing communication with other applications?
EDIT:
We also have some programs that aren't written in python, how would Django interact with these?
You need modify those python app you want to communicate.
There are some tools can do process communication in linux:
signal
share memory
file(include tcp socket)
message queue
pipe
For python, you can use tcp socket do that, this should be most easy one I guess. But that still depend on what kind data you want to communication.

How Can Python Socket Programming be used to tranfer data in Shared Hosting?

I am creating an application that uses the IOT/IOE (Internet of things) to communicate with sensors.
For this I have used Python Socket programming to Code the Sockets that communicate and JavaScript for the user end Display.
I am curious as to how I can implement this on a shared Hosting server? I know it is possible in a Dedicated Server where i have all the permissions.
If it is possible to use the sockets in shared hosting , I also want to know how feasible it is to do so ?
Any guidance will be appreciated. Thanks
If it is possible to use the sockets in shared hosting , I also want
to know how feasible it is to do so ?
As long as your socket end point is reachable in the Internet, you should be able to create and reach a socket just like the case of dedicated server. Typically, you should be able to request a public IP address on the shared host. Other than Internet reachability, sockets are application-layer semantics and so you don't need any special features.

What's the best way of communication between tornado and Python based daemon?

I use Tornado as the web server. I write some daemons with Python, which run in the server hardware. Sometimes the web server needs to send some data to the daemon and receives some computed results. There are two working:
1. Asynchronous mode: the server sends some data to the daemons, and it doesn't need the results soon. Can I use message queue to do it perfectly?
2. Synchronous mode: the server sends data to the daemons, and it will wait until it get the results. Should Iuse sockets?
So what's the best way of communication between tornado and Python based daemon?
ZeroMQ can be used for this purpose. It has various sockets for different purposes and it's fast enough to never be your bottleneck. For asynchronous you can use DEALER/ROUTER sockets and for strict synchronous mode you can use REQ/REP sockets.
You can use the python binding for this --> http://www.zeromq.org/bindings:python.
For the async mode you can try something like this from the zguide chapter 3 Router-to-dealer async routing :
In your case, the "client" in the diagram will be your web server and your daemon will be the "worker".
For synchronous you can try a simple request-reply broker or some variant to suit your need.
The diagram above shows a strictly synchronous cycle of send/recv at the REQ/REP sockets. Read through the zguide link to understand how it works. They also have a python code snippet on the page.
Depending on the scale - the simple thing is to just use HTTP and the AsyncHTTPClient in Tornado. For the request<->response case in our application we're going 300 connections/second with such an approach.
For the first case Fire and forget, you could also use AsyncHTTP and just have the server close out the connection and continue working...

Python Application that Always Listen to Specific Port Number

I want to create a python application that is always listening to a parametrized port. Whenever there is a request coming from the port, the application will parse the request and do tasks based on the request.
Is this type of application called services? (I have 0 knowledge on services). Where can I find beginner's tips and guides on this type of development?
This is called a server, there are examples at the bottom of the Python socket documentation page.
HTH.
This is socket programming. Writing sockets is cumbersome, you can use any web server written in python. My recommendation is use werkzeug, it is very simple. Meanwhile have a look at Flask which is built on top of werkzeug.
In case you are trying to build your own protocol engine twisted is one which will help you to achieve that.
You can using threads or the Twisted (arguably an easier option) framework to create a server.

Categories

Resources