joshua655 / v8cgi

Automatically exported from code.google.com/p/v8cgi
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

socket - sending string #102

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
It seems that passing a string to socket.send() method doesn't work.
I am trying to write a mongodb driver ( in js quite silly). Sending data as a 
string doesn't work, but sending the buffer created from an array works 
(mongodb accepts connection and does its work).

var data = [36,0,0,0,  1,0,0,0,  0,0,0,0,  210,7,0,0,  0,0,0,0,  97,46,112,0,  
12,0,0,0,  16,97,0,  1,0,0,0,  0];
var string = data.map(function(byte){ return 
String.fromCharCode(byte);}).join('');

socket.send(string);
socket.send(new Buffer(data));

Original issue reported on code.google.com by donkey.r...@gmail.com on 10 Nov 2011 at 9:20

GoogleCodeExporter commented 9 years ago
Sending strings should normally work; they will be serialized in UTF-8. What 
happens in your case?

Original comment by ondrej.zara on 11 Nov 2011 at 6:37

GoogleCodeExporter commented 9 years ago
I use strings as  byte streams, so the utf-8 serialization spoils it.
The utf-8 serialization is not mentioned in the api documentation, that confuse 
me.
Never mind, the socket receive is of the type Buffer, so I have to use it 
anyway.

Sorry for the chaos...:)

Original comment by donkey.r...@gmail.com on 11 Nov 2011 at 11:17

GoogleCodeExporter commented 9 years ago
Added the UTF8 notice to Socket docs.

Original comment by ondrej.zara on 11 Nov 2011 at 1:42