change to bufferedwriter and surround recieve end with try catch