本文整理汇总了Python中socket.sendall方法的典型用法代码示例。如果您正苦于以下问题:Python socket.sendall方法的具体用法?Python socket.sendall怎么用?Python socket.sendall使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类socket
的用法示例。
在下文中一共展示了socket.sendall方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: sendAPRSPacket
# 需要导入模块: import socket [as 别名]
# 或者: from socket import sendall [as 别名]
def sendAPRSPacket(socket, packet):
"""
Sends an APRS packet (just a string) to the socket specified. If an
error occurs a False is returned while a True is returned if successful.
On an error, the socket is closed as it is no longer useful.
:param socket: APRS-IS server internet socket
:param packet: String to be sent to APRS-IS
:return: Boolean
"""
try:
socket.sendall(packet)
return True
except IOError as e:
logger.error(e)
socket.close()
return False
示例2: escape
# 需要导入模块: import socket [as 别名]
# 或者: from socket import sendall [as 别名]
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
示例3: write
# 需要导入模块: import socket [as 别名]
# 或者: from socket import sendall [as 别名]
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)
示例4: escape
# 需要导入模块: import socket [as 别名]
# 或者: from socket import sendall [as 别名]
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
示例5: should_block_on_frame
# 需要导入模块: import socket [as 别名]
# 或者: from socket import sendall [as 别名]
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
示例6: send_and_receive
# 需要导入模块: import socket [as 别名]
# 或者: from socket import sendall [as 别名]
def send_and_receive(self, socket, stream, save_cookies=False):
res = []
i = socket.sendall(self.serialize())
if self.method == AjpForwardRequest.POST:
return res
r = AjpResponse.receive(stream)
assert r.prefix_code == AjpResponse.SEND_HEADERS
res.append(r)
if save_cookies and 'Set-Cookie' in r.response_headers:
self.headers['SC_REQ_COOKIE'] = r.response_headers['Set-Cookie']
# read body chunks and end response packets
while True:
r = AjpResponse.receive(stream)
res.append(r)
if r.prefix_code == AjpResponse.END_RESPONSE:
break
elif r.prefix_code == AjpResponse.SEND_BODY_CHUNK:
continue
else:
raise NotImplementedError
break
return res
示例7: send_and_receive
# 需要导入模块: import socket [as 别名]
# 或者: from socket import sendall [as 别名]
def send_and_receive(self, socket, stream, save_cookies=False):
res = []
i = socket.sendall(self.serialize())
if self.method == AjpForwardRequest.POST:
return res
r = AjpResponse.receive(stream)
assert r.prefix_code == AjpResponse.SEND_HEADERS
res.append(r)
if save_cookies and 'Set-Cookie' in r.response_headers:
self.headers['SC_REQ_COOKIE'] = r.response_headers['Set-Cookie']
# read body chunks and end response packets
while True:
r = AjpResponse.receive(stream)
res.append(r)
if r.prefix_code == AjpResponse.END_RESPONSE:
break
elif r.prefix_code == AjpResponse.SEND_BODY_CHUNK:
continue
else:
raise NotImplementedError
break
return res
示例8: write
# 需要导入模块: import socket [as 别名]
# 或者: from socket import sendall [as 别名]
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)
示例9: _internal_raw_write
# 需要导入模块: import socket [as 别名]
# 或者: from socket import sendall [as 别名]
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)
示例10: _send
# 需要导入模块: import socket [as 别名]
# 或者: from socket import sendall [as 别名]
def _send(self, msg):
"""Sends the given message to the socket."""
# socket.sendall() takes str in Python 2 and bytes in Python 3
if sys.version_info[0] >= 3:
msg = msg.encode()
try:
self._sock.sendall(msg)
except socket.error as err:
raise NagiosQueryError(err)
示例11: _internal_raw_write
# 需要导入模块: import socket [as 别名]
# 或者: from socket import sendall [as 别名]
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()
示例12: broadcast_to_all_clients
# 需要导入模块: import socket [as 别名]
# 或者: from socket import sendall [as 别名]
def broadcast_to_all_clients(self, senders_socket):
for client in self.clients_list:
socket, (ip, port) = client
if socket is not senders_socket:
socket.sendall(self.last_received_message.encode('utf-8'))
开发者ID:PacktPublishing,项目名称:Tkinter-GUI-Application-Development-Blueprints-Second-Edition,代码行数:7,代码来源:9.09_chat_server.py
示例13: write
# 需要导入模块: import socket [as 别名]
# 或者: from socket import sendall [as 别名]
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(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)
示例14: escape
# 需要导入模块: import socket [as 别名]
# 或者: from socket import sendall [as 别名]
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
示例15: output
# 需要导入模块: import socket [as 别名]
# 或者: from socket import sendall [as 别名]
def output(self, output_list):
"""Create a socket stream and send the payload as output."""
separator = output_common.get_separator(self.options['separator'], self._SEPARATORS)
line = separator.join([self.convert_item(item) for item in output_list])
if self.options['final_separator']:
line += separator
protocol = Socket._VERSIONS[self.options['ip_version']]
# TODO: handle exceptions?
s = socket.socket(protocol, socket.SOCK_STREAM)
s.connect((self.options['host'], self.options['port']))
if self.options['await_banner']:
s.recv(Socket._BANNER_LENGTH)
s.sendall(line)
s.close()