示例#1
0
文件: ws.py 项目: soitun/janus-cloud
    def __init__(self,
                 url,
                 recv_msg_cbk=None,
                 close_cbk=None,
                 protocols=None,
                 msg_encoder=None,
                 msg_decoder=None):
        # patch socket.sendall to protect it with lock,
        # in order to prevent sending data from multiple greenlets concurrently
        WebSocketClient.__init__(self, url, protocols=protocols)
        self._msg_encoder = msg_encoder or self.DEFAULT_ENCODER
        self._msg_decoder = msg_decoder or self.DEFAULT_DECODER
        lock = RLock()
        _sendall = self.sock.sendall
        self._recv_msg_cbk = recv_msg_cbk
        self._close_cbk = close_cbk

        def sendall(data):
            lock.acquire()
            try:
                _sendall(data)
            except Exception:
                raise
            finally:
                lock.release()

        self.sock.sendall = sendall

        self.connect()
        log.info('Created {0}'.format(self))
示例#2
0
    def __init__(self, host, port, path, opts):
        url = "ws://{0}:{1}{2}".format(host, port, path)
        WebSocketClient.__init__(self, url)

        self.path = path
        self.shutdown_cond = Event()
        self.opts = opts
        self.iohelper = common.StdioPipedWebSocketHelper(self.shutdown_cond, opts)
示例#3
0
    def __init__(self, scheme, host, port, path, opts):
        url = "{0}://{1}:{2}{3}".format(scheme, host, port, path)
        WebSocketClient.__init__(self, url)

        self.path = path
        self.shutdown_cond = Event()
        self.opts = opts
        self.iohelper = common.StdioPipedWebSocketHelper(self.shutdown_cond, opts)
示例#4
0
 def __init__(self, server=None, origin=None, token=None):
   self._token = token
   self._ids = itertools.count(0)
   self._results = {}
   self._streams = {}
   headers = []
   if origin is not None:
     headers.append((u"Origin", unicode(origin)))
   WebSocketClient.__init__(self, server, protocols=["http-only"], headers=headers)
示例#5
0
文件: ws.py 项目: OpenSight/IVR
    def __init__(self, url):
        self._close_event = Event()
        # patch socket.sendall to protect it with lock,
        # in order to prevent sending data from multiple greenlets concurrently
        WebSocketClient.__init__(self, url)
        self._app = None
        self._lock = RLock()
        _sendall = self.sock.sendall

        def sendall(data):
            self._lock.acquire()
            try:
                _sendall(data)
            except:
                raise
            finally:
                self._lock.release()
        self.sock.sendall = sendall
示例#6
0
文件: ws.py 项目: dulton/IVR
    def __init__(self, url):
        self._close_event = Event()
        # patch socket.sendall to protect it with lock,
        # in order to prevent sending data from multiple greenlets concurrently
        WebSocketClient.__init__(self, url)
        self._app = None
        self._lock = RLock()
        _sendall = self.sock.sendall

        def sendall(data):
            self._lock.acquire()
            try:
                _sendall(data)
            except:
                raise
            finally:
                self._lock.release()

        self.sock.sendall = sendall
示例#7
0
文件: ws.py 项目: opticoder/symmrpc
 def __init__(self, addr, serdes):
     WebSocketClient.__init__(self, addr, protocols=['http-only', 'chat'])
     self.result = None
     self.disconnected = False
     self.serdes = serdes()
示例#8
0
文件: client.py 项目: mishto/ChatApp
 def __init__(self, url, event_listeners, protocols=None, extensions=None, ssl_options=None, headers=None):
     WebSocketClient.__init__(self, url, protocols, extensions, ssl_options=ssl_options, headers=headers)
     self.listeners = event_listeners