def __init__(self, request, clientAddress, server, terminator=b'\x00'): """ TCP request handler @param request: @type request: @param clientAddress: @type clientAddress: @param server: @type server: @param terminator: @type terminator: string """ self.__mutex__ = threading.RLock() self.clientId = clientAddress # (ip,port) self.publicIp = clientAddress[0] # external ip with rp self.stopEvent = threading.Event() self.buf = b'' # contains all received data. self.bufWs = b'' # contains just ws data self.queue = Queue.Queue(0) self.socket = None self.terminator = terminator self.keepAlivePdu = '' self.lastActivityTimestamp = time.time() self.lastKeepAliveTimestamp = time.time() self.wsHandshakeSuccess = False self.wsCodec = WebSocket.WebSocketCodec(parent=self) SocketServer.BaseRequestHandler.__init__(self, request, clientAddress, server)
def __init__(self, serverAddress=None, localAddress=('', 0), inactivityTimeout=30, keepAliveInterval=20, timeout=5, proxyAddress=None, proxyUserId=b'client', selectTimeout=0.01, terminator=b'\x00', sslSupport=False, sslVersion=ssl.PROTOCOL_TLSv1, checkSsl=False, wsSupport=False, wsMaxPayloadSize=WebSocket.WEBSOCKET_MAX_BASIC_DATA1024, tcpKeepAlive=True, tcpKeepIdle=3, tcpKeepCnt=3, tcpKeepIntvl=3): """ TCP Client thread @param serverAddress: remote ip or hostname and port @type serverAddress: tuple @param localAddress: local bind on ip and port @type localAddress: tuple @param inactivityTimeout: default value of 30 seconds @type inactivityTimeout: Integer @param keepAliveInterval: default value of 20 seconds, ping or pong with websocket @type keepAliveInterval: integer @param timeout: default value of 5 second @type timeout: integer @param proxyAddress: proxy address @type proxyAddress: integer @param proxyUserId: default value : client @type proxyUserId: string @param selectTimeout: socket io timeout, default value of 0.01 @type selectTimeout: integer @param terminator: packet terminator, default value 0x00 @type terminator: integer @param wsSupport: websocket support @type wsSupport: boolean @param sslSupport: ssl support @type sslSupport: boolean @param sslVersion: default value of 1 second @type sslVersion: integer @param wsMaxPayloadSize: websocket payload size @type wsMaxPayloadSize: integer """ threading.Thread.__init__(self) self.serverAddress = serverAddress self.proxyAddress = proxyAddress # sock4 self.localAddress = localAddress self.serverDstHostname = None # proxy self.proxyDstHostname = None self.proxyConnectSuccess = False self.proxyType = PROXY_TYPE_NONE self.proxyUserId = proxyUserId # web socket self.wsCodec = WebSocket.WebSocketCodec(parent=self) self.wsSupport = wsSupport if wsSupport: self.trace('Web socket activated - version %s' % WebSocket.WEBSOCKET_VERSION) self.wsHandshakeSuccess = False self.wsKey = b'' self.wsMaxPayloadSize = wsMaxPayloadSize # ssl self.sslSupport = sslSupport self.sslVersion = sslVersion self.checkSsl = checkSsl if sslSupport: self.trace('Ssl activated - version %s' % self.sslVersion) # buffer self.buf = b'' self.bufWs = b'' self.queue = Queue.Queue(0) self.event = threading.Event() self.socket = None self.running = True self.closeSocket = False self.inactivityServer = False self.timeout = timeout self.terminator = terminator self.keepAlivePdu = b'' self.inactivityTimeout = inactivityTimeout self.keepAliveInterval = keepAliveInterval self.selectTimeout = float(selectTimeout) self.tcpKeepAlive = tcpKeepAlive self.tcpKeepIdle = tcpKeepIdle self.tcpKeepIntvl = tcpKeepIntvl self.tcpKeepCnt = tcpKeepCnt self.trace('Tcp Client Thread Initialized')