On Wed, Aug 29, 2012 at 10:14 AM, Dima Batir <[email protected]> wrote:
> Hi guys! i have to implement a client-server comunnication through
> sockets.io.
> On the socket.on('data') event, as API specifies, I receive a Buffer.
> The problem relies in how does NodeJS transform the data i receive into a
> Buffer.
> The data contains aplahnumeric characters.
> The problem is when i attempt to parse it's content, especialyy integer
> negative
> values - the buffer sees the negative sign not as a sign-bit but as a single
> byte '0x2D'
> which stands in ASCII for '-' sign. maybe there is another way to read
> bytes from a Buffer.
You mean the buffer contains string data, e.g. "-1337"? Try
socket.setEncoding('utf8'). Your data listener will get a string
(instead of a buffer) that you can parse with parseInt().
--
Job Board: http://jobs.nodejs.org/
Posting guidelines:
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en