I'm trying to bind multiple servers with python's SocketServer module:
import SocketServer
from SocketServer import BaseRequestHandler
class HTTPSERVER(BaseRequestHandler):
def handle(self):
rec = self.request.recv(1024)
if rec:
self.request.send('Got something!')
launchme = SocketServer.TCPServer(('', 82),HTTPSERVER)
launchme2 = SocketServer.TCPServer(('', 81),HTTPSERVER)
launchme3 = SocketServer.TCPServer(('', 80),HTTPSERVER)
launchme.serve_forever()
print 'reached first server'
launchme2.serve_forever()
print 'reached second server'
launchme3.serve_forever()
print 'reached third server'
When this script is launched nothing gets printed but all 3 ports are actually open:
root@user:/# netstat -pna|more
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 2751/python
tcp 0 0 0.0.0.0:81 0.0.0.0:* LISTEN 2751/python
tcp 0 0 0.0.0.0:82 0.0.0.0:* LISTEN 2751/python
But this script only serve 'Got something!' when the request is made on port 82 (first bind). What is the proper way with the SocketServer module to get all port to work?