Problems with External Results Input

I’d like to use External Results Input mechanism for sending app metrics. I wrote a API which use socket function to set up connection between App and sensu-client through port 3030, then I use write function in a while loop to writing some metrics string to that socket. I thought the process would be like:
connect -> send metrics -> send metrics -> … -> close

The first round of the loop runs quite well, I can see the check in Uchiwa. But the second round, API crashed on a “broken pipe” error.

Don’t know how could that happen, so, I went to read the Sensu source code client/socket.rb. It seems that sensu-client process will close socket after receiving external results everytime. (Is that right? so, I’m not a Ruby guy :frowning: )

So, I have to set up the connection and then close it everytime I send a single metrics. The process is something like:
connect -> send metrics -> close; connect -> send metrics -> close; …

What a waste :frowning:

So, guys, How could I fix this problem?