Added flag to control how to do IO with sockets