c# - 填充无效,即使键相同也无法删除
问题描述
我希望将消息和密钥从客户端传输到服务器。但是,我真的不明白 UDP 数据包是如何工作的。另外,有没有可能我可以通过数据包传递更多的值(超过 2 个)?
下面的代码可以获得正确的消息和密钥,并且可以解密。
this.dataIdentifier = (DataIdentifier)BitConverter.ToInt32(dataStream, 0);
int msgLength = BitConverter.ToInt32(dataStream, 4);
int keyLength = BitConverter.ToInt32(dataStream, 8);
// Read the message field
if (msgLength > 0)
this.message = Encoding.UTF8.GetString(dataStream, 12, msgLength);
else
this.message = null;
// Read the key field
if (keyLength > 0)
this.secretKey = Encoding.UTF8.GetString(dataStream, 12 + msgLength, keyLength);
else
this.secretKey = null;
但是,当我更改 keylength 的 GetString 的值时,它会显示错误。
this.dataIdentifier = (DataIdentifier)BitConverter.ToInt32(dataStream, 0);
int msgLength = BitConverter.ToInt32(dataStream, 4);
int keyLength = BitConverter.ToInt32(dataStream, 8);
// Read the message field
if (msgLength > 0)
this.message = Encoding.UTF8.GetString(dataStream, 12, msgLength);
else
this.message = null;
// Read the key field
if (keyLength > 0)
this.secretKey = Encoding.UTF8.GetString(dataStream, 12, keyLength);
else
this.secretKey = null;
客户端密钥
服务器密钥
错误
解决方案
推荐阅读
- mongodb - 将值转换为键 mongodb 聚合
- javascript - React Redux 没有在 mapStateToProps 中获取状态
- python - 无法安装特定版本的 nltk
- c# - WebAPI - 如何删除区分大小写?
- c# - CarouselView.Content 为空
- android - 对 ListView 中的项目使用单个 onClickListener 时避免嵌套布局
- java - 首次上传时超出 YouTube Data API v3 配额
- c++ - 类字符串和嵌套向量 C++
- git - 命令行 Git 工作但 VS 2017 给出 403 错误?
- c++ - 是否可以将任何类型的函数存储在一个变量中?