import cgi
import time
from random import randint, randrange
from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer

class TestRtpsServer(BaseHTTPRequestHandler):
    def do_POST(self):
        try:
            l = int(cgi.parse_header(self.headers.getheader('content-length'))[0])
            data = self.rfile.read(l)
            http_code = 123
            http_output = 'blax'
            print "Returning http_code=[%d] http_data=[%s] http_data_len=%d" % (http_code, http_output, len(http_output))
            self.send_response(http_code)
            self.send_header("Content-type", "text/plain")
            self.send_header("Content-Length", '%d' % len(http_output))
            self.end_headers()
            self.wfile.write(http_output)
            return
        except StandardError, e:
            print "EXCEPTION: %s" % e

def main():
    try:
        serv = TestRtpsServer
        print 'Running server on port 18000...' 
        server = HTTPServer(('', 18000), serv)
        server.handle_request()
    except KeyboardInterrupt:
        print '^C received, shutting down server'
        server.socket.close()

if __name__ == '__main__':
    main()



