Results 1 to 3 of 3
  1. #1
    sangio85 is offline Member
    Join Date
    Dec 2010
    Posts
    2
    Rep Power
    0

    Default Very strange exception in a socket comunication

    Hi guys.
    I have a problem. I'm running two threads on a server where I get the client a command string and then under the command because I do an action.
    In particular, I get two xml files from the client.
    In one case I have no problem. The file is properly received.
    In the other case rather than have a very strange because everything is exactly the same as the first case:

    the code is:

    XML Code:
    if("I SENT THE ACTIONS".equals(str)){
    System.out.println("S: CLIENT TELL: '" + str + "'");
    byte [] mybytearray2 = new byte [filesize];
    InputStream is2 = client.getInputStream();
    FileOutputStream fos2 = new FileOutputStream("AZIONITOSERVER.xml");
    BufferedOutputStream bos2 = new BufferedOutputStream(fos2);
    bytesRead2 = is2.read(mybytearray2,0,mybytearray2.length);
    current2 = bytesRead2;
    
    do {
    bytesRead2 = is2.read(mybytearray2, current2, (mybytearray2.length-current2));
    if(bytesRead2 >= 0) current2 += bytesRead2;
    } while(bytesRead2 > -1);
    
    bos2.write(mybytearray2, 0 , current2);
    bos2.flush();
    long end = System.currentTimeMillis();
    bos2.close();
    The excepition is:
    L'eccezione che mi capita :

    java.lang.ArrayIndexOutOfBoundsException
    at java.lang.System.arraycopy(Native Method)
    at java.io.BufferedOutputStream.write(Unknown Source)
    at agenda.bean.TCPDesktopServer.run(TCPDesktopServer. java:104)
    at java.lang.Thread.run(Unknown Source)

    where the row TCPDesktopServer.java:104 is:
    bos2.write(mybytearray2, 0 , current2);

    The strange thing is that, when not the first thread that is the identical one to this, this exception does not happen and everything works, just that I need to run both threads.
    Thaks at alla.
    Bye.

  2. #2
    mrmatt1111's Avatar
    mrmatt1111 is offline Senior Member
    Join Date
    Aug 2009
    Location
    San Jose, CA, USA
    Posts
    320
    Rep Power
    6

    Default

    how about:

    Java Code:
    bos2.write(mybytearray2, 0 , current2 - 1);
    instead?
    My Hobby Project: LegacyClone

  3. #3
    sangio85 is offline Member
    Join Date
    Dec 2010
    Posts
    2
    Rep Power
    0

    Unhappy

    I'm really sorry but there is no change in the exception and in my program if I do:
    bos2.write(mybytearray2, 0 , current2-1);

    I will became mad with this type of excemption....

Similar Threads

  1. How to handle socket Exception
    By mayank0512 in forum Networking
    Replies: 14
    Last Post: 12-21-2010, 11:31 PM
  2. Comunication between client
    By smi in forum Networking
    Replies: 3
    Last Post: 06-14-2010, 02:39 PM
  3. unreported exception (socket connection)
    By Symbiot in forum New To Java
    Replies: 7
    Last Post: 05-28-2010, 11:13 AM
  4. Comunication with server
    By Quillion in forum New To Java
    Replies: 2
    Last Post: 11-09-2009, 10:07 PM
  5. strange swt exception
    By ahmed.kotb in forum SWT / JFace
    Replies: 0
    Last Post: 04-23-2009, 10:15 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
  •