views:

87

answers:

3

There is a php script which sends a binary string to the client application:

$binary_string = pack('i',count($result_matrix));   
foreach ($result_matrix as $row)
{
    foreach ($row as $cell)
    {
        $binary_string .= pack('d',$cell);
    }
}
echo $binary_string;

Silverlight application receives $binary_string via POST protocol. How can I parse this binary string?

Or maybe there is a better way to send matrix from PHP to Silverlight?

+1  A: 

Maybe the elementary way is to send XML data? The reason is that on Silverlight side you have not only to unpack binary data, that packed with php function, but also have a knowlege how data sructure packed in php script represented in binary data.

If you will use HEX format for packing than use somethong like this to unpack data:

static byte[] UnpackHex(string hexvalue)
{
        if (hexvalue.Length % 2 != 0)
                hexvalue = "0" + hexvalue;
        int len = hexvalue.Length / 2;
        byte[] bytes = new byte[len];
        for(int i = 0; i < len; i++)
        {
                string byteString = hexvalue.Substring(2 * i, 2);
                bytes[i] = Convert.ToByte(byteString, 16);
        }
        return bytes;
}
Vokinneberg
+1  A: 

If you get the data as System.IO.Stream type, you can directly use the method read.

MasterGaurav
+1  A: 

Hello,

In the System.IO namespace you can also use the BinaryReader class. See documentation at this location BinaryReader

I think this should help. If you need more help, perhaps you should also provide some code from your silverlight side.

FrenchData