Let's retrospect a little about the nature of our beloved Python language : a cross platform language.
This mean you can use Python to develop your application easily whether you're using Linux, Windows, OSX, FreeBSD etc. Although my next statement is debatable, but I strongly believe that developing a program using programming language in its original habitat is somewhat less error prone than if you try developing it in another environment that's not its original habitat.
For example, have you ever scratch your head when somehow your website that get built in a Windows environment didn't run at all after uploading it to your shared PHP hosting? After tracking it down for several hours, finally you find the cause of error : a *.PHP file with some capital letters on it. This is not a problem in Windows, as it's case insensitive when dealing with files and folders. But that's not the case when you upload it to *nix environment : suddenly, all that capital letters must be treated as is. *nix is case sensitive when dealing with files and folders.
As Python was built on *nix environment, it derived the same case sensitive file and folder name restriction as said earlier. Sure, the problem will be dismissed if we just use *nix to build Python application. But it's not easy for one to switch to another operating system, completely replacing the current OS. Hence, there goes virtualization software where you can run any supported OSes in your current OS. It bring many great benefit such as easing the process of system integration development, where you have to integrate software coming from different OSes to bring as one solution. There are many virtualization software that you can use, but I use VirtualBox daily. It's open source and proven to run Ubuntu and Windows 7 flawlessly in my OSX box.
Developing Python in Ubuntu runs inside VirtualBox on OSX is a simple matter. It's Ubuntu. But trying to connect to Python server runs in that Ubuntu guest OS from another guest OS or host OS, is somewhat not a trivial matter. All the time, I will always need to continuously develop my Python code in Ubuntu, test its web interface using Chrome running in OSX and test my C# desktop application feature of connecting to that Python server. Have a look at Figure 1, where I try to diagramize my current situation. And also my guest OSes list below.
After googling around for sometime about the solution, I summarize the solution with this todo list:
- In Ubuntu guest OS, use NAT as the network adapter.
To bring this dialog, right click on your OS from the guest OSes list, choose Settings and choose Network tab
Setup Port Forwarding for port that your Python server listen, which is port 8888 in my case. This way, any request from your host OS (OSX Mountain Lion in my case) for port 8888 will be directed to your Ubuntu guest OS. This completely solved our problem of trying to connect from OSX using Chrome to Python server in Ubuntu.
To connect from Windows 7 guest OS to Python server in Ubuntu, simply use your host OS IP :
10.0.2.2. Remember that, from within every guest OS, your host OS will always have static IP
10.0.2.2. So, if you try to connect to
10.0.2.2:8888from Windows 7 guest OS, this means you are trying to connect to your host OS (OSX Mountain Lion in my case). But, as Port forwarding for port
8888was setup for Ubuntu, it then get directed to your Python server which already listening to port
8888. This completely solved our problem of trying to connect from C# desktop application to Python server run inside Ubuntu.
Accessing Python server reside in Ubuntu guest OS, from within Windows 7 guest OS through OSX host OS NAT Portforwarding
You can also create another port forwarding rule for another port number and it can also for another guest OS.
Stay tuned for my next article, continuing the long series of Flask Tutorial by developing Biography Application on Openshift!