Catching socket exceptions and restarting stream
Added commandline option for max retries