OK – I got it to work! This version should both send and read lines (when polled) on a single, persistent tcp socket.
I spawned a new thread to wait for the read-back. Seems to work ok here, but your milage may vary. Tested only on Mac so far, but will test on windows soon. It might be sort of a mess, but here it is anyway. Hope it works for you!