I’m trying to replicate what this C# code is doing:
public bool SendCommand(ushort command) {
// Make three byte arrays representing the values of thee integers (two unsigned shorts and an unsigned int to be exact, but it doesn't matter) called command, versionNumber and payloadSize
byte[] commandB = BitConverter.GetBytes(command);
ushort versionNumber = 1;
byte[] versionNumberB = BitConverter.GetBytes(versionNumber);
uint payloadSize = 0;
byte[] payloadSizeB = BitConverter.GetBytes(payloadSize);
// Concatenate the byte arrays into one block:
byte[] datablock = new byte[commandB.Length + versionNumberB.Length + payloadSizeB.Length];
System.Buffer.BlockCopy(commandB, 0, datablock, 0, commandB.Length);
System.Buffer.BlockCopy(versionNumberB, 0, datablock, commandB.Length, versionNumberB.Length);
System.Buffer.BlockCopy(payloadSizeB, 0, datablock, commandB.Length + versionNumberB.Length, payloadSizeB.Length);
// Send the datablock through TCP, don't mind what this is m_stream is doing. Just trust me, that's what it does.
m_stream.Write(datablock, 0, datablock.Length);
}
It is using .NET features, namely BitConverter.GetBytes, to convert the integers “command”, “versionNumber” and “payloadSize” into byte arrays, then combines them into one byte array, and sends that.
In UE4, to send things over TCP the Socket->Send functionality is used. However, it takes a uint8* as a parameter for the data it is sending, and not a byte array. I could simply use uint8(myInteger) to convert that “command” integer into a thing that is sendable, but I need to combine the three integers before sending them, like what System.Buffer.BlockCopy does, so that the raw binary data sent by TCP would be the same as the one sent by that C# script.
How do I do that?
p.s. and how do I determine the size of the data to send? I’m an absolute noob in this entire networking/tcp/whatever thing.
EDIT: byte is apparently non-existent in UE4, and i need to use chars instead. how? please help I’m drowning here