Sajeetharan
Sajeetharan

Reputation: 222582

How to make two different python scripts to run on the same port?

Currently I'm developing web services in python using web.py, that serves different functions. Something like

BigQueryService.py
LogicImplementer.py
PostgreService.py

Each service works perfectly when running on the local machine. After deploying on the server, due to I'm refering an other python script, it returns a module error.

Since we have to run all the services on the same port, I pasted all the scripts into a single file named Engine and made it to work using the command

$ nohup python Engine.py 8080 &

Is there any better way to structure the service in web.py? Or is there a way to run all the individual scripts on the same port?

Upvotes: 2

Views: 1159

Answers (1)

If each service creates its own listener/server socket on the port, then the answer is no. You will need to use the equivalent of an app server that has a single server port and distributes the incoming request to the relevant app (running on the server) based typically on the relative path - so e.g. http://myserver.net:8080/bqs paths get passed to your BiqQueryService, /li to LinkImplementor, /pgs to PostgreService. Flask will do something like this, I'm sure other web service frameworks will too. The server will handle all the communication stuff, pass requests to the app (e.g. bqs) and handle sending response to the client.

Upvotes: 2

Related Questions