JSON

Aug 8, 2012 at 4:55 PM

Hi,
  I see wired issue: I add a command that send the following message to web:
public class WindowOpenedMessage {          public int Width { get; set; }           public int Height { get; set; }        public string Image { get; set; }}

Now from my command (in websocket server) I send to client by:


var response = CommandKeys.OPEND_RESPONSE + " " + SerializeObject(new WindowOpenedMessage{               Width = commandInfo.Width,Height = commandInfo.Height,Image = commandInfo.Image});


targetSession.SendResponseAsync(response);

I see that if I send the requist with an Image after convert to base64 (tobase64(myimage)) have same size if I send requist with an Image as is without convert to base64 (myimage), mean that I see that if i send an image after convert to base64 webclient will get same size as if I send image without convert to base64.


It is wired because convert to base64 should add 33% (3k will come to 4K data).
Can explain this pls?, how I can send the string or byte[] as is without change it to base64?

Aug 8, 2012 at 5:06 PM

Sorry, I cannot understand you.

But I need to tell you SuperWebSocket(websocket) supported binary fragment, but most browsers don' have this API.

Aug 8, 2012 at 5:22 PM

what I say is no matter what string I send I get same in web:

1. send file image data(read image file data and send it as byte[] ), without any changes, and any convert to web client via web socket server

2.send same file data but this time after convert the file data to base64 string before sending

In both ways above I get same data as base64 string??? , the question is who convert the data to base64? is SerializeObject() do that? why? :(

Aug 8, 2012 at 6:04 PM

Yes, I think so.

JSON.NET must convert byte[] to string, and the perfer way is BASE64 encoding.

Aug 8, 2012 at 6:08 PM

Is there any way to convert to string but not base64 (it is adding 30% of data- and this does not make any science)

Aug 9, 2012 at 6:36 AM

Base64 is best one, you can compare it with hex encoding.