Send byte array data in websocket

Dec 29, 2011 at 11:47 AM
Edited Dec 29, 2011 at 11:50 AM

Hi

I want to send a  byte array data  to server  and I convert array data to string  look like that

// ws is WebSocket and it is connected to server

ws.send(String.fromCharCode( 0,120, 127, 128, 192, 200, 254));

But when I received data  from server I received data look like that:

[0,120,127,194,128,195,128,195,136,195,190]

I concluded as follows

  • 0-127     : it received value
  • 128-191 : it add 194 in front of value
    • ( when you send 1 byte value 128 you received 2 byte [194 and 128] )   
    • ( when you send 1 byte value 191 you received 2 byte [194 and 191] )
  • 192-255   : it add 195 and (value - 64)    
    • ( when you send 1 byte value 192 you received 2 byte [195 and 128] )   
    • ( when you send 1 byte value 255 you received 2 byte [195 and 191] )

I think the browser automatic added this for encoding .Is that right? Can we disable this feature?

PS: I use latest chrome browser and secure Websocket

Coordinator
Dec 29, 2011 at 12:00 PM

WebSocket always use UTF8 encoding, you cannot change it.