python socket 数据传输小记
2017-09-27 12:24
316 查看
In python 3, bytes strings and unicodestrings are now two different types. Since sockets are not aware of string encodings, they are using raw bytes strings, that have a slightly differentinterface from
unicode strings.
So, now, whenever you have a unicode stringthat you need to use as a byte string, you need toencode() it. And whenyou have a byte string, you need to decode it to use it as a regular(python 2.x) string.
Unicode strings are quotes enclosedstrings. Bytes strings are b"" enclosed strings
When you use client_socket.send(data),replace it by client_socket.send(data.encode()). When you get datausing data = client_socket.recv(512), replace it by data =client_socket.recv(512).decode()
python作者 在python3 更新时 相对于2做出了改进:
将字符串变成了 Unicode,文件默认编码变成了utf-8
将str 与 bytes 做出了明确区分,str就是单纯的Unicode格式的字符,bytes就是单纯的二进制(在python2里面 Unicode与str类型,str与bytes类型的关系很混乱,具体想了解,自行百度)
unicode strings.
So, now, whenever you have a unicode stringthat you need to use as a byte string, you need toencode() it. And whenyou have a byte string, you need to decode it to use it as a regular(python 2.x) string.
Unicode strings are quotes enclosedstrings. Bytes strings are b"" enclosed strings
When you use client_socket.send(data),replace it by client_socket.send(data.encode()). When you get datausing data = client_socket.recv(512), replace it by data =client_socket.recv(512).decode()
python作者 在python3 更新时 相对于2做出了改进:
将字符串变成了 Unicode,文件默认编码变成了utf-8
将str 与 bytes 做出了明确区分,str就是单纯的Unicode格式的字符,bytes就是单纯的二进制(在python2里面 Unicode与str类型,str与bytes类型的关系很混乱,具体想了解,自行百度)
相关文章推荐
- Python的struct使用-解决socket的通讯限制了传输数据的长度
- [Android通信]基于socket的聊天app(三):传输json数据
- 使用Socket进行设备间点对点连接传输数据
- Python爱好者 socket模块传输文件 -
- Unity3D中的socket通信之九(账号密码/数据传输过程中的加密解密)
- C#实现Socket传输简单数据
- SocketChannel类(用于阻塞或非阻塞式传输数据) 创建SocketChannel要使用SocketChannel类的静态工厂方法。 SocketChannel open():创建未连接的
- flex 数据传输 httpservice, webservice, RemoteObject, socket
- python实现简单socket程序在两台电脑之间传输消息的方法
- 树莓派通过socket传输图片流-Python
- Android客户端向Python服务器以POST方式传输数据
- 使用DatagramSocket与DatagramPacket传输数据
- Unity3D 游戏引擎之C#使用Socket与HTTP连接server数据传输包
- WIfi Socket数据传输
- 网络数据传输socket和http优缺点
- SOCKET传输数据、文件
- Socket与底层数据传输实现
- python网络编程之数据传输UDP实例分析
- 使用DatagramSocket与DatagramPacket传输数据 分类: B1_JAVA 2013-10-12 13:00 1936人阅读 评论(0) 收藏
- Android与Java 服务器使用Socket协议实现Json数据传输