我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用socket.sendall()。
def should_block_on_frame(self, frame): if not should_debug_code(frame.f_code): return False # It is still possible that we're somewhere in standard library code, but that code was invoked by our # internal debugger machinery (e.g. socket.sendall or text encoding while tee'ing print output to VS). # We don't want to block on any of that, either, so walk the stack and see if we hit debugger frames # at some point below the non-debugger ones. while frame is not None: # There is usually going to be a debugger frame at the very bottom of the stack - the one that # invoked user code on this thread when starting debugging. If we reached that, then everything # above is user code, so we know that we do want to block here. if frame.f_code in DEBUG_ENTRYPOINTS: break # Otherwise, check if it's some other debugger code. filename = path.normcase(frame.f_code.co_filename) is_debugger_frame = False for debugger_file in DONT_DEBUG: if is_same_py_file(filename, debugger_file): # If it is, then the frames above it on the stack that we have just walked through # were for debugger internal purposes, and we do not want to block here. return False frame = frame.f_back return True
def escape(self, data): """\ This generator function is for the user. All outgoing data has to be properly escaped, so that no IAC character in the data stream messes up the Telnet state machine in the server. socket.sendall(escape(data)) """ for byte in iterbytes(data): if byte == IAC: yield IAC yield IAC else: yield byte # - incoming data filter
def write(self, data): """\ Output the given string over the serial port. Can block if the connection is blocked. May raise SerialException if the connection is closed. """ if not self._isOpen: raise portNotOpenError self._write_lock.acquire() try: try: self._socket.sendall(to_bytes(data).replace(IAC, IAC_DOUBLED)) except socket.error, e: raise SerialException("connection failed (socket error): %s" % e) # XXX what exception if socket connection fails finally: self._write_lock.release() return len(data)
def escape(self, data): """\ this generator function is for the user. all outgoing data has to be properly escaped, so that no IAC character in the data stream messes up the Telnet state machine in the server. socket.sendall(escape(data)) """ for byte in data: if byte == IAC: yield IAC yield IAC else: yield byte # - incoming data filter
def escape(self, data): """\ This generator function is for the user. All outgoing data has to be properly escaped, so that no IAC character in the data stream messes up the Telnet state machine in the server. socket.sendall(escape(data)) """ for byte in data: if byte == IAC: yield IAC yield IAC else: yield byte # - incoming data filter
def test_ssl_close(self): def serve(listener): sock, addr = listener.accept() sock.recv(8192) try: self.assertEqual(b'', sock.recv(8192)) except greenio.SSL.ZeroReturnError: pass sock = listen_ssl_socket() server_coro = eventlet.spawn(serve, sock) raw_client = eventlet.connect(sock.getsockname()) client = ssl.wrap_socket(raw_client) client.sendall(b'X') greenio.shutdown_safe(client) client.close() server_coro.wait()
def test_ssl_unwrap(self): def serve(): sock, addr = listener.accept() self.assertEqual(sock.recv(6), b'before') sock_ssl = ssl.wrap_socket(sock, tests.private_key_file, tests.certificate_file, server_side=True) sock_ssl.do_handshake() self.assertEqual(sock_ssl.recv(6), b'during') sock2 = sock_ssl.unwrap() self.assertEqual(sock2.recv(5), b'after') sock2.close() listener = eventlet.listen(('127.0.0.1', 0)) server_coro = eventlet.spawn(serve) client = eventlet.connect(listener.getsockname()) client.sendall(b'before') client_ssl = ssl.wrap_socket(client) client_ssl.do_handshake() client_ssl.sendall(b'during') client2 = client_ssl.unwrap() client2.sendall(b'after') server_coro.wait()
def write(self, data): """\ Output the given byte string over the serial port. Can block if the connection is blocked. May raise SerialException if the connection is closed. """ if not self.is_open: raise portNotOpenError with self._write_lock: try: self._socket.sendall(to_bytes(data).replace(IAC, IAC_DOUBLED)) except socket.error as e: raise SerialException("connection failed (socket error): %s" % (e,)) return len(data)
def _internal_raw_write(self, data): """internal socket write with no data escaping. used to send telnet stuff.""" with self._write_lock: self._socket.sendall(data)
def _internal_raw_write(self, data): """internal socket write with no data escaping. used to send telnet stuff.""" self._write_lock.acquire() try: self._socket.sendall(data) finally: self._write_lock.release()
def write(self, data): """\ Output the given byte string over the serial port. Can block if the connection is blocked. May raise SerialException if the connection is closed. """ if not self.is_open: raise portNotOpenError with self._write_lock: try: self._socket.sendall(to_bytes(data).replace(IAC, IAC_DOUBLED)) except socket.error as e: raise SerialException("connection failed (socket error): {}".format(e)) return len(data)
def send_progress(socket, min, max, current): if socket: s = "p:min={},max={},current={}\n".format(min, max, current) try: r = socket.sendall(s) except: print ("Error sending progress information")
def send_file(): try: socket.connect((HOST,PORT)) except Exception,e: print 'Error connecting to server:%s'% e full_name = '/tmp/' + image_name + '.tar' print 'send:' + full_name try: socket.send(full_name,1024) data = socket.recv(1024) except Exception,e: print 'Error,socket send and recv file name failed:%s' % e return if data == 'ready': file_to_send = open(full_name,'rb') while True: data = file_to_send.read(4096) if not data: break; socket.sendall(data) file_to_send.close() socket.send('',1024) socket.close()
def _sendall(self, msg): return self._sock_wrap(self._socket.sendall)(msg)
def _send_success_response(rpc_session, socket, request, result): response = rpc_session.create_success_response(request[RPC_IDX_MSG_ID], result) socket.sendall(response)
def _send_error_response(rpc_session, socket, request, emsg): response = rpc_session.create_error_response(request[RPC_IDX_MSG_ID], str(emsg)) socket.sendall(response) # Network controller singleton
def sendAll(self, socket, string): socket.sendall(string + TERMINAL)