跳转到内容
View in the app

A better way to browse. Learn more.

彼岸论坛

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.
欢迎抵达彼岸 彼岸花开 此处谁在 -彼岸论坛

[问与答] 自定义协议的 magic number 超过 8 字节,如何在大小端系统正确解释

发表于

假如协议头: 0xDEADBEEFDEADBEEFEF 9 个字节,而用于网络和主机字节序转换的函数 htonl/ntohl 最多能转换一个 long 的长度即 8 个字节

那么如何在大小端系统中传输这个自定义协议数据时,如何保证都能正确解释这个协议头(能够正确判断协议头对,自定义协议基于 TCP )

期望:

  • TCP 数据:data=0xDEADBEEFDEADBEEFEF
  • 小端系统:some_func(data) == 0xDEADBEEFDEADBEEFEF
  • 大端系统:some_func(data) == 0xDEADBEEFDEADBEEFEF

结论:协议头正确

Featured Replies

No posts to show

创建帐户或登录来提出意见

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.