file - java socket. How to server know client close stream -


I want to write a transfer file socket program in java.

When I turn off the inputstream in the client, know how to shut the server outstream.

Here's my code: Try the client

  {byte [] data = new byte [1024]; InputStream = socket.getInputStream (); FileOutputStream fos = New FileOutputStream ("/mnt/sdcard/UML.doc"); BufferedOutputStream Boss = New BufferedOutputStream (fos); Integer = 0; While ((count = is.read (data))! = -1 & amp;; has been canceled) {total + = count; Published progress ("+ +" (integer) ((total * 100) / size); Fos.write (data, 0, count); } If (Canceled) {is}. Close (); Fos.close (); //socket.close (); PDialog.dismiss (); File file = new file ("mnt / sdcard / UML.doc"); File.delete (); Cancel = false; }} Hold (exception e) {Log.e ("error:", e.getMessage ()); }   

......

server

  BufferedInputStream bis = null; BIS = new bufferInputTream (new fileinputstream (mimefile)); BISRed (MyBiTiEre, 0, MyBiTerere Length); OS = s.getOutputStream (); Integer = 0; Try {O.S. Write (Mybietier, 0, Mybyteerere, Langh); // os.flush (); } Hold (SocketException e) {os.flush (); Tv.setText ("aaaaa"); }   

......

But when I turn off the inputstream

When the customer closes InputStream in the middle of a transmission, a SocketException will be thrown on the server side.

Comments