官方文档对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的区别的更多相关文章

  1. Python中send()和sendall()的区别

    Python中send()和sendall()的区别 估计每个学习Python网络编程的人,都会遇到过这样的问题: send()和sendall()到底有什么区别? send()和sendall()原 ...

  2. python socket编程入门(编写server实例)+send 与sendall的区别与使用方法

    python 编写server的步骤: 1. 第一步是创建socket对象.调用socket构造函数.如: socket = socket.socket( family, type ) family参 ...

  3. Python中type与Object的区别

    Python中type与Object的区别 在查看了Python的API后,总算明白了.现在总结如下: 先来看object的说明: Python中关于object的说明很少,甚至只有一句话: clas ...

  4. Python中生成器和迭代器的区别(代码在Python3.5下测试):

    https://blog.csdn.net/u014745194/article/details/70176117 Python中生成器和迭代器的区别(代码在Python3.5下测试):Num01–& ...

  5. Python中的is和==的区别,==判断值是否相等,is判断地址是否一致

    Python中的is和==的区别 Python中的对象包含三要素:id.type.value. 其中id用来唯一标示一个对象,type标识对象的类型,value是对象的值. is判断的是a对象是否就是 ...

  6. 基于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 ...

  7. Python中的is和==的区别

    Python中的is和==的区别 1. is 是比较内存地址id() a = "YongJie" b = "YongJie" print(id(a)) #233 ...

  8. python中_new_()与_init_()的区别

    __new__方法的使用 只有继承于object的新式类才能有__new__方法,__new__方法在创建类实例对象时由Python解释器自动调用,一般不用自己定义,Python默认调用该类的直接父类 ...

  9. python中break和continue的区别

    python中break和continue的区别   break和continue 1.break 意思为结束循环   例: i = 0 while i<10:     i+=1     if ...

随机推荐

  1. C#UDP异步通信

    using SetingDemo.LogHelp;using SetingDemo.SingleRowDeclare;using System;using System.Collections.Gen ...

  2. ajax 请求二进制流 图片

    <html xmlns="http://www.w3.org/1999/xhtml"><head runat="server">    ...

  3. SQLServer从渣仔到小白

    一.将查询结果插入到另一张表 1. 查询结果插入新表 select * into tableA from tableB where … 2. 查询结果插入已经存在的表 insert into tabl ...

  4. 本地存储和vuex使用对比

    1. sessionStorage sessionStorage 方法针对一个 session 进行数据存储.当用户关闭浏览器窗口后,数据会被删除. 用法: 储存: 1. 点(.)运算符        ...

  5. 关于dataset

    举个栗子: <div id="cost" data-drink="coffee" data-food="sushi" data-mea ...

  6. 如何检测浏览器是否能用ActiveX

    var xhr=false; function CreateXHR(){ try{ //检查能否用activexobject xhr=new ActiveXObject("msxml2.XM ...

  7. Django drf:cbv源码、resful规范及接口、drf使用、response源码、序列化

    一.cbv源码分析 二.resful规范 三.django中写resful的借口 四.drf写resful的借口 五.APIVIew源码分析 六.drf之序列化 一.cbv源码分析 -CBV和FBV ...

  8. js修改元素的属性

    <script type="text/javascript"> //给id为nice的元素 添加title属性并赋值为"测试title" funct ...

  9. js获取div基础元素

    1.js获取div元素 clientHeight 获取对象的高度,不计算任何边距.边框.滚动条,但包括该对象的补白. clientLeft 获取 offsetLeft 属性和客户区域的实际左边之间的距 ...

  10. C#实现10进制转2进制

    这几天在复习计算机原理,看到二进制忽然想到二进制转10进制的公式,然后转念一想10进制转二进制的公式好像没印象,那索性自己写出来. 结果学渣的我发现,并不能写出来!什么数列,对数,xx函数忘得一干二净 ...