Python websocket.ABNF.OPCODE_BINARY Examples
The following are 4
code examples of websocket.ABNF.OPCODE_BINARY().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
websocket.ABNF
, or try the search function
.
Example #1
Source File: ws_client.py From python-base with Apache License 2.0 | 5 votes |
def write_channel(self, channel, data): """Write data to a channel.""" # check if we're writing binary data or not binary = six.PY3 and type(data) == six.binary_type opcode = ABNF.OPCODE_BINARY if binary else ABNF.OPCODE_TEXT channel_prefix = chr(channel) if binary: channel_prefix = six.binary_type(channel_prefix, "ascii") payload = channel_prefix + data self.sock.send(payload, opcode=opcode)
Example #2
Source File: ws_client.py From python-base with Apache License 2.0 | 5 votes |
def update(self, timeout=0): """Update channel buffers with at most one complete frame of input.""" if not self.is_open(): return if not self.sock.connected: self._connected = False return r, _, _ = select.select( (self.sock.sock, ), (), (), timeout) if r: op_code, frame = self.sock.recv_data_frame(True) if op_code == ABNF.OPCODE_CLOSE: self._connected = False return elif op_code == ABNF.OPCODE_BINARY or op_code == ABNF.OPCODE_TEXT: data = frame.data if six.PY3: data = data.decode("utf-8", "replace") if len(data) > 1: channel = ord(data[0]) data = data[1:] if data: if channel in [STDOUT_CHANNEL, STDERR_CHANNEL]: # keeping all messages in the order they received # for non-blocking call. self._all.write(data) if channel not in self._channels: self._channels[channel] = data else: self._channels[channel] += data
Example #3
Source File: stream.py From pymarketstore with Apache License 2.0 | 5 votes |
def _subscribe(self, ws, streams): msg = msgpack.dumps({ 'streams': streams, }) ws.send(msg, opcode=ABNF.OPCODE_BINARY)
Example #4
Source File: ws_client.py From aws-kube-codesuite with Apache License 2.0 | 5 votes |
def update(self, timeout=0): """Update channel buffers with at most one complete frame of input.""" if not self.is_open(): return if not self.sock.connected: self._connected = False return r, _, _ = select.select( (self.sock.sock, ), (), (), timeout) if r: op_code, frame = self.sock.recv_data_frame(True) if op_code == ABNF.OPCODE_CLOSE: self._connected = False return elif op_code == ABNF.OPCODE_BINARY or op_code == ABNF.OPCODE_TEXT: data = frame.data if six.PY3: data = data.decode("utf-8") if len(data) > 1: channel = ord(data[0]) data = data[1:] if data: if channel in [STDOUT_CHANNEL, STDERR_CHANNEL]: # keeping all messages in the order they received for # non-blocking call. self._all += data if channel not in self._channels: self._channels[channel] = data else: self._channels[channel] += data