I'm sending messages trough a socket connection to a device. The device 
sends a message on which i need to respond. 
    
This is my code for opening a socket connection:

    var lPORT = 4102;
    // Create a server instance, and chain the listen function to it
    net.createServer(function(sock) {
    
        // We have a connection - a socket object is assigned to the 
connection automatically
        console.log('TCP LISTENER hearing on: ' + sock.remoteAddress +':'+ 
sock.remotePort);
    
        // Event handler: incoming data
        sock.on('data', function(data) {
            sock.allowHalfOpen = true;
        sock.pipe(sock);
        var sockwrite = sock.write(data+'\r\n');
        if (sockwrite == true) {
            console.log(''+data);
            }
    
        // Write incoming messages to logfile.
        var log = fs.createWriteStream('pin.log', {'flags': 'a'});
        log.write(data+'\n\r\n\r');
    
        // Push incoming messages to client
       io.of('/process').emit( 'broadcast_msg', ''+data);
    
        });
    
        // Event handler: close connection
        sock.on('close', function(data) { 
            console.log('[LISTENER] Connection paused.');
        });
    
    }).listen(lPORT); 

Beneath is the code for connecting to that socket connection and sending 
the data. But that data is not physicly send to the socket, i checked this 
with wireshark. The message send from this code is not send.
    
    var returnsock = net.createConnection(4102, function() {
        returnsock.write(msg); 
    });


The point is, that the data send from "returnsock.write(msg);" **does** 
come trough in the code above, i can see that when i view my console.log. 
So, "var sockwrite = sock.write(data+'\r\n');" comes back with "true".
    
My question is: Why is the data that is send from "returnsock.write(msg)" 
come tru to the server, but is not send inside the socket with "var 
sockwrite = sock.write(data+'\r\n')"?
    
Thanks in advance!

-- 
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 nodejs@googlegroups.com
To unsubscribe from this group, send email to
nodejs+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

Reply via email to