Question

What's the easiest way to establish an emulated TCP connection over HTTP with python 2.7.x?

Server: a python program on pythonanywhere (or some analogue) free hosting, that doesn't provide a dedicated ip. Client: a python program on a Windows PC.

Connection is established via multiprocessing.BaseManager and works fine when testing both server and client on the same machine.

Is there a way to make this work over HTTP with minimal additions to the code?

P.S. I need this for a grid computing project. P.P.S. I'm new to python & network & web programming, started studying it several days ago.

Found this: http://code.activestate.com/recipes/577643-transparent-http-tunnel-for-python-sockets-to-be-u/. Appears to be exactly what I need, though I don't understand how to invoke setup_http_proxy() on server/client side. Tried setup_http_proxy("my.proxy", 8080) on both sides, but it didn't work.

Also found this: http://docs.python.org/2/library/httplib.html. What does the HTTPConnection.set_tunnel method actually do? Can I use it to solve the problem in question?

Was it helpful?

Solution

Usage on the client:

setup_http_proxy("THE_ADRESS", THE_PORT_NUMBER) # address of the Proxy, port the Proxy is listening on 

The code wraps sockets to perform an initial HTTP CONNECT request to the proxy setup to get an HTTP Proxy to proxy the TCP connection for you but for that you'll need a compliant proxy (most won't allow you to open TCP connections unless it's for HTTPS). HTTPConnection.set_tunnel basically does the same thing.

For your use case, a program running on free hosting, this just won't work. Your free host probably will only allow you to handle http requests, not have long running processes listen for tcp connections(which the code assumes). You should rethink your need to tunnel and organize your communication to post data (and poll for messages from the server, unless they're answers to the stuff you post). Or you can purchase a VPS hosting that will give you more control over what you can host remotely.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top