The Socket.Receive() method will fill a buffer with as much data as it can fit, or as much data is available, whichever is lower.
If you know all your messages are under 2048 bytes then you could declare your buffer as follows:
byte[] buffer = new byte[2048];
int bytesReceived = 0;
// ... somewhere later, getting data from client ...
bytesReceived = deviceSocket.Receive( buffer );
Debug.WriteLine( String.Format( "{0} bytes received", bytesReceived ) );
// now process the 'bytesReceived' bytes in the buffer
for( int i = 0; i < bytesReceived; i++ )
{
Debug.WriteLine( buffer[i] );
}
Of course you probably want to do something more than write the bytes to the debug output, but you get the idea :)
You still need to be aware that you may get incomplete data, if the client broke the message into multiple packets then one might come through (and be received) and then later another. It's always good to have some way of telling the server how much data to expect, then it can assemble the complete message before processing it.