byte[] imageBytes = File.ReadAllBytes("myImage.jpg"); NetworkMessage message = new NetworkMessage(); message.AddBytes(imageBytes);
float[] sensorData = {10.1f, 20.2f, 30.3f, 40.4f}; byte[] sensorBytes = new byte[sensorData.Length * sizeof(float)]; Buffer.BlockCopy(sensorData, 0, sensorBytes, 0, sensorBytes.Length); NetworkMessage message = new NetworkMessage(); message.AddBytes(sensorBytes);In this example, we have an array of sensor data in float format. We convert it to a byte array using the Buffer.BlockCopy method and then append it to a network message using the AddBytes method. The package library used in these examples is not specified, but it could be any networking library that supports message construction with byte array support. Some examples of such libraries include the .NET Socket class, Lidgren.Network, and Unity Networking.