def run(self):
     try:
         self.__s=SockServer(SocketModeFactory.TCP, ControlHandler,1)
         #self.__s.taskManager.config(autokick=False)
         self.__s.setReuseAdress()
         self.__addr = ("localhost",self.port)
         self.__s.bind(self.__addr)
         Log.info("control interface started: %s"%(self.__addr,))
         
         self.__s.start()
     except socket.error:
         Log.error("control interface could not bound on %s",(self.__addr,))
 def connectRemote(self,connection,respHeader,c):
     if self._socketType=="UNIX":
         sc=SockClient(self._socket,self.uri,self)
     
     else:
         sc=SockClient(self._socket,connection,self)
     
         
     self.sockClient=sc
     sc.start()    
     WebSocketHandler.handshakeSuccessful(self, respHeader,c)
     Log.info("".join([str(self._socketType)," bridge established to ",str(self.uri)]))        
def bootstrap():
    def cmd(cmd):
        print("cmd",cmd)
        
    def exit_():
        print("exit keystroke detected...")
        s.stop()        
        
    #generate folder structure
    pathlist=["../resources","../resources/logs"]
    for i in pathlist:
        if not os.path.exists(i):
            os.mkdir(i)
    
    #init config
    StdConfig.getInstance()
    
    try:
        policy=PolicyControl.getInstance()
    except ParseError as e:
        Log.error("Policy XML malformed")
         
    Authentication.init()
    proxyWSPort=StdConfig.getInstance().getProxyPort()
    adress=("localhost",proxyWSPort)
    
        
    #s=ThreadedSockServer(SocketModeFactory.TCP,DynamicThreadPoolTaskManager, WebSocketProxyHandler,policy.getMaxConnections())
    s=SockServer(SocketModeFactory.TCP, WebSocketProxyHandler,policy.getMaxConnections())
    if StdConfig.getInstance().isControlInterfaceEnabled():
        ci = ControlInterface(StdConfig.getInstance().getControlPort())
        ci.start()
    it=InputThread(exit_,cmd)
    s.setReuseAdress()
    try:
        s.bind(adress)
    except socket.error:
        Log.error("Socket could not be bound on port %s"%proxyWSPort)
        
    
    Log.info("websocket proxyserver started: %s"%(adress,))
    it.start()
    
    
    s.start()
    Log.info("websocket proxyserver stopped: %s"%(adress,))
    sys.exit(0)
 def disconnected(self, reason):
     Log.info("".join([str(self._socketType)," bridge closed for ",str(self.uri)," > ",reason]))
     if hasattr(self,"sockClient"): 
         self.sockClient.stop()
     WebSocketHandler.disconnected(self, reason)