V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
octalempyrean
V2EX  ›  Python

Python Socket UDP 读取数据问题

  •  
  •   octalempyrean · 2019-07-26 15:51:01 +08:00 · 1564 次点击
    这是一个创建于 1707 天前的主题,其中的信息可能已经有所发展或是发生改变。
    1. 用 recvfrom 读取到的数据和调试助手测试接收到的数据不一样,为什么呢?
    2. recvfrom 读取到的数据怎么转换处理下,表示不会啊,例如下面字节处的数据怎么提取出来呢?

    Byte17~Byte24 Byte25~Byte32 Byte33~Byte41 Byte42~Byte48 Byte49~…
    X 正峰值点 Y 正峰值点 X 负峰值点 Y 负峰值点 曲线点
    点坐标( x,y )总共占 8 个字节,横坐标和纵坐标用单精度浮点数表示。

    recvfrom 读取到的数据

    b'\x01\x05\xfd\xe5\x00\x00\x00\x00\x00\x00\x00\x00\xde\x01\x00\x00\x01f\xf7\xe9B:ah?\xb0\x8a\xcb?f\xf7\xe9B5\xcd\x0fA"Q\n\xbf\xa2\xc6U\xbf\xb2\xae\x9bB\xd4\t AM\xf0;\xbf\xeeZ A\xaa*<\xbf\xda\xac A^i<\xbf\xc5\xfe A\xda\xab<\xbf\xdfO!Ar\xf1<\xbf\xca\xa1!Ao9=\xbf\xb6\xf3!A\x08\x83=\xbf\xa2E"Ad\xcd=\xbf\x8d\x97"A\xab\x17>\xbf\xa7\xe8"A\x1da>\xbf\x92:#A\x10\xa9>\xbf~\x8c#A\
    ……

    调试助手测试接收到的数据
    01 05 FD E5 00 00 00 00 00 00 00 00 E1 01 00 00 01 19 F3 E9 42 DE 80 37 3F 8E 58 B1 3F 19 F3 E9 42 4E D1 0F 41 1D 4C 01 BF C6 2D 4B BF 14 AE E4 41 F0 16 20 41 BE 91 30 BF DB 68 20 41 A7 EA 30 BF C7 BA 20 41 4A ……
    3 条回复    2019-07-26 17:48:23 +08:00
    julykitt
        1
    julykitt  
       2019-07-26 16:23:16 +08:00
    你这个两边数据是一样的吧,只是 python debug 显示不一样。你把 python 接收到的,用二进制方式写到文件里,在用 hex 工具看看
    raysmond
        2
    raysmond  
       2019-07-26 17:43:13 +08:00
    import struct

    x = struct.unpack('f', bytes[0:4])
    y = struct.unpack('f', bytes[4:8])
    octalempyrean
        3
    octalempyrean  
    OP
       2019-07-26 17:48:23 +08:00
    @julykitt #1 我也感觉是 dubug 显示问题,可是为什么呢?暂时没在电脑旁
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5489 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 33ms · UTC 09:02 · PVG 17:02 · LAX 02:02 · JFK 05:02
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.