Results 1 to 3 of 3
- 12-05-2010, 11:20 AM #1
Member
- Join Date
- Dec 2010
- Posts
- 2
- Rep Power
- 0
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:
The excepition 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();
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.
- 12-05-2010, 10:40 PM #2
how about:
instead?Java Code:bos2.write(mybytearray2, 0 , current2 - 1);
My Hobby Project: LegacyClone
- 12-05-2010, 10:48 PM #3
Member
- Join Date
- Dec 2010
- Posts
- 2
- Rep Power
- 0
Similar Threads
-
How to handle socket Exception
By mayank0512 in forum NetworkingReplies: 14Last Post: 12-21-2010, 11:31 PM -
Comunication between client
By smi in forum NetworkingReplies: 3Last Post: 06-14-2010, 02:39 PM -
unreported exception (socket connection)
By Symbiot in forum New To JavaReplies: 7Last Post: 05-28-2010, 11:13 AM -
Comunication with server
By Quillion in forum New To JavaReplies: 2Last Post: 11-09-2009, 10:07 PM -
strange swt exception
By ahmed.kotb in forum SWT / JFaceReplies: 0Last Post: 04-23-2009, 10:15 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks