推荐学习书目
› 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 · Jul 26, 2019 · 2693 views
    This topic created in 2617 days ago, the information mentioned may be changed or developed.
    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 replies  •  2019-07-26 17:48:23 +08:00
    julykitt
        1
    julykitt  
       Jul 26, 2019
    你这个两边数据是一样的吧,只是 python debug 显示不一样。你把 python 接收到的,用二进制方式写到文件里,在用 hex 工具看看
    raysmond
        2
    raysmond  
       Jul 26, 2019
    import struct

    x = struct.unpack('f', bytes[0:4])
    y = struct.unpack('f', bytes[4:8])
    octalempyrean
        3
    octalempyrean  
    OP
       Jul 26, 2019
    @julykitt #1 我也感觉是 dubug 显示问题,可是为什么呢?暂时没在电脑旁
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1027 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 47ms · UTC 18:14 · PVG 02:14 · LAX 11:14 · JFK 14:14
    ♥ Do have faith in what you're doing.