The Full Code:
var net = require('net');
var server = net.createServer(function(c) { //'connection' listener
console.log('Tentativa de Conexao ao Servidor');
c.on('data',function(data){
console.log(data);
var str = "0184008000280000000000009a102404";
var a = [];
for (var i = 0; i <str.length; i += 2)
a.push("0x"+ str.substr (i, 2));
console.log(a);
c.write(a);
c.pipe();
});
c.on('end', function() {
console.log('Disconectou do Servidor');
});
console.log("Conexões: "+server.connections);
//c.pipe();
});
server.listen(9118, function() { //'listening' listener
console.log('Servidor Iniciado');
});
On Thursday, September 5, 2013 4:22:41 PM UTC-3, Felipe Silveira wrote:
>
> Hello Guys,
>
> I'm making a small server that listens for requests and responds devices.
> The Code is this:
>
> Now I can read the data received on the server but when I send them,
> transform them from HEX to Byte, follow the lines of code
>
> var str = '0184008000280000000000009a102404 ";
> var a = [];
>
> for (var i = 0; i <str.length; i + = 2) {
> a.push ("0x" + str.substr (i, 2));
> }
>
>
> but nodejs give the error:
>
> net.js: 450
> throw new TypeError ("First argument must be a buffer or a string.");
> ^
> TypeError: First argument must be a buffer or a string.
> at Socket.write (net.js: 450:11)
> at Socket. <anonymous> (/ var / www / node.js: 35:7)
> at Socket.emit (Events.js: 67:17)
> at TCP.onread (net.js: 367:14)
>
> Someone knows the solution?
> Thank you a lot for pacient.
>
--
--
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
---
You received this message because you are subscribed to the Google Groups
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.