python sendall_Python socket.sendall方法代码示例

本文详述了Python中socket.sendall方法的用法,通过17个精选代码示例,展示了如何在不同场景下使用该方法。涉及发送APRS包、数据逃逸、串口通信等方面,适用于解决Python网络通信中的数据发送问题。
摘要由CSDN通过智能技术生成

本文整理汇总了Python中socket.sendall方法的典型用法代码示例。如果您正苦于以下问题:Python socket.sendall方法的具体用法?Python socket.sendall怎么用?Python socket.sendall使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在模块socket的用法示例。

在下文中一共展示了socket.sendall方法的17个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: sendAPRSPacket

​点赞 6

# 需要导入模块: 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

开发者ID:FaradayRF,项目名称:Faraday-Software,代码行数:21,

示例2: escape

​点赞 6

# 需要导入模块: 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

开发者ID:cedricp,项目名称:ddt4all,代码行数:18,

示例3: write

​点赞 6

# 需要导入模块: 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)

开发者ID:FSecureLABS,项目名称:Jandroid,代码行数:18

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值