0

I'm trying to send some messages to a server. That's what I do

for(var i=0; i<100; i++){
  var post={
    att1       : var.att[i].att1,
    att2       : var.att[i].att2,
    att3       : var.att[i].att3,
    att4       : var.att[i].att4
  }

  sock.write(JSON.stringify(post));
}

But I get this strange error

events.js:72
        throw er; // Unhandled 'error' event
              ^
Error: write EPIPE
    at errnoException (net.js:904:11)
    at Object.afterWrite (net.js:720:19)
logout

Why this happens? Is the buffer of the socket full?

3
  • Post events.js:72. Could you be writing after closing the socket? Perhaps something you should've waited for a callback to do? Commented Jul 3, 2014 at 19:50
  • It's because the "throw er;" is not being catch. This is why you get Unhandled error. You need to use try catch. Witch the catch you will be able to get a more readable error. Commented Jul 3, 2014 at 19:50
  • Thanks I'll try to catch the error Commented Jul 3, 2014 at 19:57

1 Answer 1

1

It usually means that the other end closed the connection unexpectedly. In any case, you were writing to the closed socket.

Also, 100.length is not a valid JavaScript.

Sign up to request clarification or add additional context in comments.

1 Comment

Sure sorry... I Trying to clarify the example and I forgot to delete the length

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.