import java.net.*; import java.io.*; public class Server { public static void main (String [] args ) throws IOException { int filesize=1022386; int bytesRead; int currentTot = 0; try { ServerSocket serverSocket = new ServerSocket(9999); Socket socket = serverSocket.accept(); System.out.println("Accepted connection : " + socket); BufferedReader br=new BufferedReader(new InputStreamReader(socket.getInputStream())); String temp=br.readLine(); System.out.println("The mesage from client is::"+temp); PrintStream pr=new PrintStream(socket.getOutputStream()); String str = "acknowledgement from server"; pr.println(str); byte [] bytearray = new byte [filesize]; InputStream is = socket.getInputStream(); FileOutputStream fos = new FileOutputStream("d:/here/sreethu.doc"); BufferedOutputStream bos = new BufferedOutputStream(fos); bytesRead = is.read(bytearray,0,bytearray.length); currentTot = bytesRead; do { bytesRead = is.read(bytearray, currentTot, (bytearray.length-currentTot)); if(bytesRead >= 0) currentTot += bytesRead; } while(bytesRead > -1); bos.write(bytearray, 0 , currentTot); bos.flush(); bos.close(); socket.close(); } catch(Exception ex) { } } }
try{ // fancycoding } catch(Exception ex) { ??? WHY EMPTY ??? ex.printStackTrace(); // this should be in there to see what is wrong (unless you have a proper logging, then the exception should be listed there) }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)