Results 1 to 2 of 2
  1. #1
    gisler is offline Member
    Join Date
    Apr 2009
    Rep Power

    Default socket DataOutput problems


    For my client/server program i am having problems with my client recieving the correct amount of data. when i step through the client it does not always receive all the bytes for the first stream. Edit: My client program will just freeze after during the 2nd transfer or the 6th. its at random times. the file does transfer but information on the clients screen does not update.

    this is the code for my server

    Java Code:
             FileInputStream fileInput = new FileInputStream(file);  //create fileInputStream of file
                        DataOutputStream stream = new DataOutputStream(socket.getOutputStream()); //creat DataOutputStream of the socket
                        byte[] bb = new byte[10000];   //create a byte that stores 10000 bytes
                        start = System.currentTimeMillis();  //get the current time in milliseconds
                        while (true) {                        //loop untill file is sent
                            int result =;   //read 10000 bytes of the file into result
                            if (result == -1) {              //check if end of file has been read
                                break;                          //exit while loop
                            stream.write(bb, 0, result);       //send 10000 bytes of file to the client

    Java Code:
          DataInputStream dataInput = new DataInputStream(socket.getInputStream()); //create a new instance of a DataInputStream in order to get data from server
            FileOutputStream fileOutput = new FileOutputStream(path.trim() + "\\" + newFileName.trim()); //create new instance of FileOutputStream to write the file to the clients computer
            byte[] bb = new byte[10000];           //create a new instance of a byte
            while (true) {
                int result =;     //read 10000 bytes and place bytes in variable called result
                fileOutput.write(bb, 0, result);        //write a file on input
                if (fileSize == result) {               //check if result is equal to the filesize
                    break;                              //break while loop
                fileSize -= result;                     //subtract result from fileSize
    edit: also if i step through the server the client and the serve work just fine. I can't figure out why my client will occasionally just freeze on me.
    Last edited by gisler; 12-17-2009 at 09:04 PM.

  2. #2
    gisler is offline Member
    Join Date
    Apr 2009
    Rep Power



    the problem seems to actually be the client is recieving to many bytes. usually about 40. any reason why this might happen?

Similar Threads

  1. append response to the request from Socket and write to another socket
    By in forum Networking
    Replies: 3
    Last Post: 04-17-2009, 07:02 PM
  2. help about Socket
    By fahien_akim in forum New To Java
    Replies: 0
    Last Post: 04-16-2009, 10:41 AM
  3. Socket
    By rob in forum New To Java
    Replies: 1
    Last Post: 03-19-2009, 02:24 PM
  4. Socket
    By vortex in forum New To Java
    Replies: 2
    Last Post: 05-25-2008, 06:41 AM
  5. XML through a socket
    By Heather in forum XML
    Replies: 2
    Last Post: 07-04-2007, 09:31 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts