I use a union structure.
// create a union to hold the data
union Buffer
{
long longNumber;
byte longBytes[4];
};
Buffer buffer; // create an instance of the union
buffer.longNumber = 0xaabbccdd; // assign a value to the long number
Now the longBytes array contains the pieces of the long number.
Send the longBytes array using the write(data, length) function.
Have an identical union at the receiving end. Read the bytes into the buffer.longBytes array. Now the buffer.longNumber variable holds the long number.
The same method works for float data type. Just replace the long longNumber with
float floatNumber.