add reconnect method and use it to automatically reconnect if connection/pipe was broken (e.g., by ctrl+c )