def start_local_http_server(port, handler=RequestHandler):

    server = HTTPServer(("127.0.0.1", port), handler)
    server.allow_reuse_address = True
    server.auth_code = None
    server.error = None
    return server
Example #2
0
def create_test_http_server():
    server = HTTPServer(('localhost', 8222), TestHandler)
    server.allow_reuse_address = True
    thread = Thread(target=server.serve_forever, args=[0.01])
    thread.setDaemon(True)
    thread.start()
    return server
Example #3
0
def start_server():
    os.chdir('static')
    httpd = HTTPServer(("", PORT), XSSHandler)
    httpd.allow_reuse_address = True
    t = threading.Thread(target=httpd.serve_forever)
    t.daemon = True
    t.start()

    url = ngrok.connect(port=PORT, proto='http')
    url = url.replace('http', 'https')
    XSSHandler.url = url
    return url
Example #4
0
def run():

    try:
        wsd = WSServer(("", 9999), on_newConnection)
        wsd.start()
        httpd = HTTPServer(("", 8888), RequestHandler)
        httpd.allow_reuse_address = True
        t = threading.Thread(target=httpd.serve_forever)
        t.setDaemon(True)
        t.start()
        print("Running HttpServer on port 8888")

        while True:
            alltasksdone = True
            for task in tasks:
                if task.ready() and not task.done:
                    execute(task)

                if alltasksdone and not task.done:
                    alltasksdone = False

            if alltasksdone:
                break

            time.sleep(1)

        print("all tasks done.")

    except (KeyboardInterrupt, SystemExit):
        print("Main: Exception occured.")

    finally:
        print("\nshutdown HttpServer")
        httpd.shutdown()
        print("shutdown WebSocketServer")
        wsd.shutdown()
        exit()
Example #5
0
class MailResponder(ipc.Responder):
  def __init__(self):
    ipc.Responder.__init__(self, MAIL_PROTOCOL)

  def invoke(self, message, request):
    if message.name == 'send':
      request_content = request['message']
      response = "Sent message to %(to)s from %(from)s with body %(body)s" % \
                 request_content
      return response
    elif message.name == 'replay':
      return 'replay'

class MailHandler(BaseHTTPRequestHandler):
  def do_POST(self):
    self.responder = MailResponder()
    call_request_reader = ipc.FramedReader(self.rfile)
    call_request = call_request_reader.read_framed_message()
    resp_body = self.responder.respond(call_request)
    self.send_response(200)
    self.send_header('Content-Type', 'avro/binary')
    self.end_headers()
    resp_writer = ipc.FramedWriter(self.wfile)
    resp_writer.write_framed_message(resp_body)

if __name__ == '__main__':
  mail_server = HTTPServer(SERVER_ADDRESS, MailHandler)
  mail_server.allow_reuse_address = True
  mail_server.serve_forever()
Example #6
0
        with open(rendered_file_path, 'w') as result_file:
            result_file.write(output)

        with open(rendered_file_path, 'rb') as file:
            self.wfile.write(file.read())
        '''
        print(current_path)
        print("printed path in second condition " + self.path)
        print("rendered file path " + rendered_file_path)
        '''


httpd = HTTPServer(('localhost', int(sys.argv[1])),
                   MyHandler,
                   bind_and_activate=False)
httpd.allow_reuse_address = True
httpd.daemon_threads = True
httpd.server_bind()
httpd.server_activate()
print("Store server running at port: " + sys.argv[1])

if __name__ == "__main__":
    try:
        while True:
            httpd.serve_forever()
            print("Store server restarted at port: " + sys.argv[1])

            httpd = HTTPServer(('localhost', int(sys.argv[1])),
                               MyHandler,
                               bind_and_activate=False)
            httpd.allow_reuse_address = True