firosServer.py
Go to the documentation of this file.
00001 # MIT License
00002 #
00003 # Copyright (c) <2015> <Ikergune, Etxetar>
00004 #
00005 # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files
00006 # (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge,
00007 # publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
00008 # subject to the following conditions:
00009 #
00010 # The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
00011 #
00012 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00013 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
00014 # FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00015 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00016 
00017 from BaseHTTPServer import HTTPServer
00018 
00019 from include.logger import Log
00020 
00021 from include.server.requestHandler import RequestHandler
00022 
00023 
00024 class FirosServer:
00025     ## \brief FIROS http server
00026     # \param self
00027     # \param ip address
00028     # \param port to listen to
00029     def __init__(self, address="0.0.0.0", port=8000):
00030         self.address = address
00031         self.port = port
00032         self.stopped = False
00033 
00034         Protocol = "HTTP/1.0"
00035 
00036         server_address = (self.address, self.port)
00037 
00038         RequestHandler.protocol_version = Protocol
00039         self.httpd = HTTPServer(server_address, RequestHandler)
00040 
00041     def start(self):
00042         ## \brief start FIROS http server
00043         # \param self
00044         sa = self.httpd.socket.getsockname()
00045         Log("INFO", "\nServing HTTP on", sa[0], "port", sa[1], "...")
00046         while not self.stopped:
00047             self.httpd.handle_request()
00048 
00049     def close(self):
00050         ## \brief stop FIROS http server
00051         # \param self
00052         self.stopped = True


firos
Author(s): IƱigo Gonzalez, igonzalez@ikergune.com
autogenerated on Thu Jun 6 2019 17:51:04