Python中send和sendall的区别
官方文档对socket模式下的socket.send() 和 socket.sendall()解释如下:
sock.sendall(string[, flags])
Send data to the socket. The socket must be connected to a remote socket. The optional flags argument has the same meaning as for recv() above. Unlike send(), this method continues to send data from string until either all data has been sent or an error occure. None is returned on success. On error, an exception is raised, and there is no way to datermine how much data, if any, was successfully sent.
尝试发送string的所有数据, 成功则返回None, 失败则抛出异常。
socket.send(string [, flags])
Send data to the socket. The socket must be connected to a remote socket. The optional flags argument has the same meaning as for recv() above. Returns the number of bytes snet. Applications are responsible for checking that all data has been sent; if only some of the data was transmitted, the application needs to attempt delivery of the remaining data.
send()的返回值式发送的字节数量, 这个数量值可能小于要发送的string的字节数,也就是说可能无法发送string中所有的数据。如果有错误,则会抛出异常。
所以, 下面两段代码是等价的:
sock.sendall("Hello world\n")
buffer = "Hello world\n"
while buffer:
bytes = sock.send(buffer)
buffer = buffer[bytes:]
Python中send和sendall的区别的更多相关文章
- Python中send()和sendall()的区别
Python中send()和sendall()的区别 估计每个学习Python网络编程的人,都会遇到过这样的问题: send()和sendall()到底有什么区别? send()和sendall()原 ...
- python socket编程入门(编写server实例)+send 与sendall的区别与使用方法
python 编写server的步骤: 1. 第一步是创建socket对象.调用socket构造函数.如: socket = socket.socket( family, type ) family参 ...
- Python中type与Object的区别
Python中type与Object的区别 在查看了Python的API后,总算明白了.现在总结如下: 先来看object的说明: Python中关于object的说明很少,甚至只有一句话: clas ...
- Python中生成器和迭代器的区别(代码在Python3.5下测试):
https://blog.csdn.net/u014745194/article/details/70176117 Python中生成器和迭代器的区别(代码在Python3.5下测试):Num01–& ...
- Python中的is和==的区别,==判断值是否相等,is判断地址是否一致
Python中的is和==的区别 Python中的对象包含三要素:id.type.value. 其中id用来唯一标示一个对象,type标识对象的类型,value是对象的值. is判断的是a对象是否就是 ...
- 基于python中staticmethod和classmethod的区别(详解)
例子 ? 1 2 3 4 5 6 7 8 9 10 11 12 13 class A(object): def foo(self,x): print "executing foo ...
- Python中的is和==的区别
Python中的is和==的区别 1. is 是比较内存地址id() a = "YongJie" b = "YongJie" print(id(a)) #233 ...
- python中_new_()与_init_()的区别
__new__方法的使用 只有继承于object的新式类才能有__new__方法,__new__方法在创建类实例对象时由Python解释器自动调用,一般不用自己定义,Python默认调用该类的直接父类 ...
- python中break和continue的区别
python中break和continue的区别 break和continue 1.break 意思为结束循环 例: i = 0 while i<10: i+=1 if ...
随机推荐
- SQL Server循环插入
一个SQL循环插入的代码,运行正常: BEGIN DECLARE @idx AS INT; DECLARE @NodeName nvarchar(255); DECLARE @OtherName nv ...
- Kirinriki 2017多校
由于每个串的长度为5000,我们去枚举两个自串的对称点(这里注意一下,枚举的时候有两种情况的区间),然后用尺取法爬一遍. ac代码: #include<iostream> #include ...
- php 测试php连接redis集群的案例
<?php$redis_list = ['12.24.18.2:6379'];$client = new RedisCluster(NUll,$redis_list);echo $client- ...
- Advanced Installer 开始-程序那里增加,快捷方式、卸载软件、官方网站
. 这个是效果.
- vue中的绑定class和微信小程序中的绑定class的区别
微信小程序 小程序里面的class与style绑定,遵循HTML特性绑定,有关于HTML绑定.在进行class与style绑定时,可以直接绑定,也可以带上逻辑与,或者三元运算进行条件控制 JS dat ...
- 【解决方案】K2 BPM_赋能房地产业务高效运营_全球领先的工作流引擎
随着房地产行业步入成熟期,行业整合及转型速度变快,房企要在数字经济的背景下实现稳步发展,需要由原本的粗放式管理逐渐向集团性管理.精细化管控转变,从决策分析.项目开发到市场营销的各个环节,都要求更为科学 ...
- DX使用随记--GroupControl
1. 创建按钮: (1)添加引用:Imports DevExpress.XtraEditors.ButtonsPanelControl (2)添加按钮语句:GroupControl1.CustomHe ...
- SSISDB8:查看SSISDB记录Package执行的消息
在执行Package时,SSISDB都会创建唯一的OperationID 和 ExecutionID,标识对package执行的操作和执行实例(Execution Instance),并记录opera ...
- mORMot学习笔记3 数据集转Json
usesSynCommons, SynDB, SynOleDB; procedure TForm1.DataToJsonClick(Sender: TObject); var Conn: TOleDB ...
- 在cmd下import cv2报错——OpenCV实现BRISK
平台:win10 x64 +JetBrains PyCharm 2018.2.4 x64 +Anaconda3(python3.7.0+opencv3.4.5) Issue说明:同学发了个python ...