Module tcpcom :: Class HTTPServer
[frames] | no frames]

Class HTTPServer

source code

        object --+            
                 |            
threading._Verbose --+        
                     |        
      threading.Thread --+    
                         |    
                 TCPServer --+
                             |
                            HTTPServer

Instance Methods
 
getHeader1(self) source code
 
getHeader2(self) source code
 
onStop(self) source code
 
__init__(self, requestHandler, serverName='PYSERVER', port=80, isVerbose=False)
Creates a HTTP server (inherited from TCPServer) that listens for a connecting client on given port (default = 80).
source code
 
getClientIP(self)
Returns the dotted IP of a connected client.
source code
 
onStateChanged(self, state, msg) source code
 
debug(self, msg) source code

Inherited from TCPServer: disconnect, isConnected, isTerminated, loopForever, run, sendMessage, setTimeout, terminate

Inherited from threading.Thread: __repr__, getName, isAlive, isDaemon, is_alive, join, setDaemon, setName, start

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __setattr__, __sizeof__, __str__, __subclasshook__

Static Methods
 
getServerIP()
Returns the server's IP address (static method).
source code

Inherited from TCPServer: getIPAddress, getVersion

Class Variables

Inherited from TCPServer: CONNECTED, LISTENING, MESSAGE, PORT_IN_USE, TERMINATED, isVerbose

Properties

Inherited from threading.Thread: daemon, ident, name

Inherited from object: __class__

Method Details

__init__(self, requestHandler, serverName='PYSERVER', port=80, isVerbose=False)
(Constructor)

source code 


Creates a HTTP server (inherited from TCPServer) that listens for a connecting client on given port (default = 80). 
Starts a thread that handles and returns HTTP GET requests. The HTTP respoonse header reports the given server name 
(default: "PYSERVER")

requestHandler() is a callback function called when a GET request is received.
Signature:  msg, stateHandler = requestHandler(clientIP, filename, params)

Parameters:                
    clientIP: the client's IP address in dotted format
    filename: the requested filename with preceeding '/'
    params: a tuple with format: ((param_key1, param_value1), (param_key2, param_value2), ...)  (all items are strings)

Return values:
    msg: the HTTP text response (the header is automatically created) 
    stateHandler: a callback function that is invoked immediately after the reponse is sent.
      If stateHandler = None, nothing is done. The function may include longer lasting server 
      actions or a wait time, if sensors are not immediately ready for a new measurement.
    
Call terminate() to stop the server. The connection is closed by the server at the end of each response. If the client connects,
but does not send a request within 5 seconds, the connection is closed by the server.

Parameters:
  • port - the IP port where to listen (0..65535)
  • stateChange - the callback function to register
  • endOfBlock - character indicating end of a data block (default: '')
  • isVerbose - if true, debug messages are written to System.out, default: False
Overrides: object.__init__

getClientIP(self)

source code 

Returns the dotted IP of a connected client. If no client is connected, returns empty string.

debug(self, msg)

source code 
Overrides: TCPServer.debug