Updating socket connection logic to explicitly close at end of transfer.