Results 1 to 5 of 5
  1. #1
    blutao is offline Member
    Join Date
    Jun 2010
    Posts
    9
    Rep Power
    0

    Default Socket Programming

    New to Java. The following client app connects to a server ( server app on another pc) on a port, but is unable to send the file.( intend to build a p2p app). PL do help. Appreciate. ( it compiles fine)







    c
    FileOutputStream fos = new FileOutputStream(" new " + fName3 );
    BufferedOutputStream bos = new BufferedOutputStream(fos);
    byteRead = is.read( byteOfArray,0,byteOfArray.length );
    currtB = byteRead;

    do {
    byteRead = is.read(byteOfArray, currtB, ( byteOfArray.length-currtB));
    if( byteRead >= 0 ) currtB += byteRead;
    } while(byteRead > -1);
    bos.write( byteOfArray, 0 , currtB);
    bos.flush();
    long stopTimer = System.currentTimeMillis();
    System.out.println(startTimer - stopTimer);
    bos.close();

    logger.info(" Retrieve Command Issued By The Client For The File : "+ fName3 + " To The Server ");

    socket.close();

    break;

    case 4:
    notifyAll();
    socket.close();

    break;

    default:
    System.exit(0);

    }

    }

    } catch (Exception e) {
    e.printStackTrace();
    }
    }
    }
    Last edited by blutao; 10-08-2010 at 06:27 AM.

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,415
    Rep Power
    25

    Default

    is unable to send the file.
    Are there errors? Can you explain what happens when you execute the program?

    Please put your code in code tags. Info here: Java Forums - BB Code List

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    So this will not return.

    Java Code:
    os.write(byteOfArray,0,byteOfArray.length);

  5. #5
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Are you sure that the array populated properly.

    Can you post that specific code segment. Looking through the complete code is bit of mess, it's too long. ;)

Similar Threads

  1. Socket Programming Vulnerability!
    By nigamsir in forum Networking
    Replies: 1
    Last Post: 03-16-2010, 04:38 PM
  2. socket programming
    By Omarero in forum New To Java
    Replies: 5
    Last Post: 12-18-2008, 04:58 PM
  3. Socket programming
    By ikoko in forum New To Java
    Replies: 1
    Last Post: 10-16-2008, 02:50 PM

Posting Permissions

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