我有一个C++服务器,它接收来自用C#编写的客户机的字节数组(我使用的是SFML套接字)。在客户机中,我使用System.Bitconverter对数据包信息进行编码。
我如何从C++服务器上的数据包中提取信息,因为它是作为string/char[]接收的。有了C#中的位转换器,我就可以做Bitconverter.GetBytes (...)了。
我不太擅长C++,所以我为nooby的问题道歉。任何帮助都将不胜感激!提前感谢!
客户端(为统一游戏引擎编写):
// - Sending this Player's data: -
byte[] buff = new byte[7 * sizeof(float) + 3 * sizeof (int)];
int tag = 1;
int curSize = 0;
Buffer.BlockCopy(BitConverter.GetBytes(tag), 0, buff, curSize, sizeof (int));
curSize += sizeof(int);
Buffer.BlockCopy(BitConverter.GetBytes(id), 0, buff, curSize, sizeof(int));
curSize += sizeof(int);
Buffer.BlockCopy(BitConverter.GetBytes(GetComponent<controls>().killedID), 0, buff, curSize, sizeof(int));
curSize += sizeof(int);
Buffer.BlockCopy(BitConverter.GetBytes(transform.position.x), 0, buff, curSize, sizeof(float));
curSize += sizeof(float);
Buffer.BlockCopy(BitConverter.GetBytes(transform.position.y), 0, buff, curSize, sizeof(float));
curSize += sizeof(float);
Buffer.BlockCopy(BitConverter.GetBytes(transform.position.z), 0, buff, curSize, sizeof(float));
curSize += sizeof(float);
Buffer.BlockCopy(BitConverter.GetBytes(transform.eulerAngles.x), 0, buff, curSize, sizeof(float));
curSize += sizeof(float);
Buffer.BlockCopy(BitConverter.GetBytes(GetComponentInChildren<Camera> ().transform.eulerAngles.y), 0, buff, curSize, sizeof(float));
curSize += sizeof(float);
Buffer.BlockCopy(BitConverter.GetBytes(transform.eulerAngles.z), 0, buff, curSize, sizeof(float));
curSize += sizeof(float);
Buffer.BlockCopy(BitConverter.GetBytes(myGun.transform.eulerAngles.x), 0, buff, curSize, sizeof(float));
curSize += sizeof(float);
sendData(buff);
}
private void sendData(byte[] data)
{
udp.Send(data, data.Length);
}https://stackoverflow.com/questions/59155386
复制相似问题