views:

25

answers:

2

I have a apache webserver, and we need to develop a module in it (using mod_python or mod_wsgi). It will ofcourse handle the requests sent as http GET/POST. However, we would like this module to ALSO handle messages sent by another remote applications which are NOT http based. That is, the body of the those tcp packets may just be a json or xml formatted message. That remote application just keeps spitting out notifications every once in a while and is not expecting any responses from the apache module.

I was wondering if I can spawn two threads in my module (one receiving messages from apache when http messages are received on port 80, the other thread listening on some other port .. say 2000 .. and my remote machine is configured to send to port 2000). Another possibility is that I run a separate application on my apache machine listening on port 2000. When it receives notification, I wrap it into http message and send it back to myself on port 80.

I guess the question is: Is my module limited to getting messages only via the apache (from port 80) or can my apache module also listen on other ports ? If there's a simpler solution, please let me know. Thanks.

A: 

You can setup apache to listen on different ports, using the VirtualHost directive:

Listen 80
Listen 2000

<VirtualHost *:80>
    ServerName www.example.com
    WSGIScriptAlias / /path/to/script.wsgi

    <Location /my/location>
    ...
    </Location>
</VirtualHost>

<VirtualHost *:2000>
    ServerName www.example.com
    WSGIScriptAlias / /path/to/script.wsgi

    <Location /my/location>
    ...
    </Location>
</VirtualHost>

More info here.

However, it might be easier to listen on port 80 and differentiate by using different paths, like so:

<VirtualHost *:80>
    WSGIScriptAlias /normal /path/to/script.wsgi
    WSGIScriptAlias /notifications /path/to/script.wsgi
    WSGIApplicationGroup %{GLOBAL}
    ...
</VirtualHost>
the_void
Thanks for the answer. But the notifications are not coming in as a http://url/notifications. They are just normal tcp/ip messages with some data (could be a text file or xml file). There is no http header in the messages. Would the line "WSGIScriptAlias / /path/to/script.wsgi" still send such messages to the script.wsgi ?
G.A.
A: 

Because Apache in most configurations is a multi process web server, you can't just listen on a separate socket from your Python code as multiple processes would attempt to do the same and so they would clash.

Technically you could use mod_wsgi daemon mode for your WSGI application and run it with a single process to avoid the multiprocess issue, but would still question whether this is a good idea and the completely separate process distinct from Apache is probably better.

Graham Dumpleton