So you want a web server on a local machine with a TCP backend to control the remote device. You also want some API to be able to access the server problematically.
If this is correct, you will need: - a web2py application with functions decorated as services http://web2py.com/books/default/chapter/29/10#Remote-procedure-calls - background tasks for communication with the remote device http://web2py.com/books/default/chapter/29/4#Scheduler-%28experimental%29 How you implement the TCP communication is up to you. It could be C++ or Python or whatever you like. It has nothing to do with the apache httpd server. It would just be a part of the backend, executed outside of the user request to the http server. It could be an external command called from a task.