问题描述
我希望从客户端向服务器传输消息和密钥。但是,我不太了解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;
但是,当我更改键长的GetString的值时,它将显示错误。
this.dataIdentifier = (DataIdentifier)BitConverter.ToInt32(dataStream,keyLength);
else
this.secretKey = null;
客户端密钥
服务器密钥
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)