I am a newbie to nodejs concepts. I am studying the use of unix sockets as a means of communication between C and nodejs. In C: I am sending 1000 iterations of a 100byte long message.
in nodejs: I am receiving 4 data callbacks of size: 1st callback: 10000 2nd callback: 32200 3rd callback: 32200 4th callback: 25600
I understand that I am able to receive the complete data. However, how do I get this data in 1000 callbacks each with size 100 bytes (the same way I am sending it).
Code Reference
Server in C (Partial):
char buf[100];
int loop_count = 0;
memset(buf,0xA5,sizeof(buf));
while(loop_count < 1000) {
rc = sizeof(buf);
if (write(cl, buf, rc) != rc) {
if (rc > 0) fprintf(stderr,"partial write");
else {
perror("write error");
exit(-1);
}
}
++loop_count;
}
Client in nodejs:
var net = require('net');
var client = net.createConnection("temp");
#temp is the socket file name
client.on("connect", function() {
console.log("Connection established");
});
client.on("data", function(data) {
console.log("Found data "+data);
});
via Ramdas
No comments:
Post a Comment