javascript - Send binary string via WebSocket in Chrome -


i have been trying send binary data via websocket in vain.

the data:

$buff=chr(1); $buff.=chr(2); $buff.=chr(0); $buff.=chr(0); $buff.=chr(0); $buff.=chr(6); $buff.=chr(1); $buff.=chr(6); $buff.=chr(0); $buff.=chr(192); $buff.=chr(0); $buff.=chr(1); 

it works using php, can't achieve want using php, can rely on javascript.

php
works fine:

$length = strlen($this->buff); $sent = socket_write($socket, $this->buff, $length); 

js
1 not:

var data="<?= $buff ?>"; web_socket_swf_location="websocketmain.swf"; var ws= new websocket("ws://10.0.0.60:502");  ws.onopen=function(){      ws.send(data); } 

desired data sent:

01 02 00 00 00 06 01 06 00 c0 00 01 

data sent websocket:

47 45 54 20 2f 20 48 54 54 50 2f 31 2e 31 0d 0a 48 6f 73 74  3a 20 31 30 2e 30 2e 30 2e 36 30 3a 35 30 32 0d 0a 43 6f 6e  6e 65 63 74 69 6f 6e 3a 20 55 70 67 72 61 64 65 0d 0a 50 72  61 67 6d 61 3a 20 6e 6f 2d 63 61 63 68 65 0d 0a 43 61 63 68  65 2d 43 6f 6e 74 72 6f 6c 3a 20 6e 6f 2d 63 61 63 68 65 0d  0a 55 70 67 72 61 64 65 3a 20 77 65 62 73 6f 63 6b 65 74 0d  0a 4f 72 69 67 69 6e 3a 20 68 74 74 70 3a 2f 2f 6c 6f 63 61  6c 68 6f 73 74 0d 0a 53 65 63 2d 57 65 62 53 6f 63 6b 65 74  2d 56 65 72 73 69 6f 6e 3a 20 31 33 0d 0a 55 73 65 72 2d 41  67 65 6e 74 3a 20 4d 6f 7a 69 6c 6c 61 2f 35 2e 30 20 28 57 ... 

how can send right data using websocket?


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -