Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Super Contributor
lyon819
Posts: 253
Registered: ‎08-19-2010
My Device: BB10, Playbook, 9900, 9800, 9700, 9550, 9530, 9500, 8700.
Accepted Solution

Fail to transfer several files.

[ Edited ]

Problem:

Could not transfer several files to the server in the same time?

 

I can use java machine to transfer and receive files between different pc.

I can transfer a single files between BlackBerry 9800/9900 and PC.

I can transfer several files name between BlackBerry 9800/9900 and PC.

 

However, 

Socket client always catch is not driven in the line.

 

DataOutputStream dos = new DataOutputStream(connection.openDataOutputStream());
dos.writeUTF(OnlyfileName);
byte[] buffer = loadFiles(filePath);
int len = buffer.length;
///////////////////// catch is not driven //////////////////////////////////////////////////////
out = connection.openOutputStream();
out.write(buffer, 0, len);
out.flush();

 

Socket server always catch is not driven in the line.

 

FileOutputStream fos = new FileOutputStream(new File(dir, filename));// the same result as above.

bos = new BufferedOutputStream(fos);
 ////////////////////////// catch is not driven ///////////////////////////////////////
bytesRead = is.read(receivedData, 0, receivedData.length);
current = bytesRead;
do {
bytesRead = is.read(receivedData, current,(receivedData.length - current));
if (bytesRead >= 0)
current += bytesRead;
} while (bytesRead > -1);

 

Could anyone give a hint how to solve the issue?

Does anyone have this kind of experience?

 

Thank your attention.

 

 

-Fight with BB10
Please use plain text.
Developer
peter_strange
Posts: 19,608
Registered: ‎07-14-2008
My Device: Not Specified

Re: Fail to transfer several files.

[ Edited ]

Are you sure it hangs?  This will be in a try catch, can you confirm that the catch is not driven?

 

Note also, that the 'read' line

 

bytesRead = is.read(receivedData, 0, receivedData.length);

 

may block until it receives receivedData.length bytes.

Please use plain text.
Super Contributor
lyon819
Posts: 253
Registered: ‎08-19-2010
My Device: BB10, Playbook, 9900, 9800, 9700, 9550, 9530, 9500, 8700.

Re: Fail to transfer several files.

Thx peter.

 

u r right.

It is not hang up. It is not catched.

 

Stop in the "read" for sure.

 

But, the line should be fine. I could not find a reason why the "read' line does not work.

 

Could u give me more hint?

 

Thx,

 

-Fight with BB10
Please use plain text.
Developer
peter_strange
Posts: 19,608
Registered: ‎07-14-2008
My Device: Not Specified

Re: Fail to transfer several files.

There is one way you might actually die without hitting the break point and that is in you are running this code on the Event Thread.  The OS will kill processes that attempt this.  You should see a message in the log and typically on the screen regarding this.  As you have not commented on this message, I have presumed you have not hit it.  But we had better check!

 

So please add the following code

 

if ( Application.isEventDispatchThread() ) {

Dialog.alert("Running on the Event Thread, this will not work");

}

just before the statement you think never comes back.  

 

Then run a test as follows:

 

Put breakpoints on the line that you think never comes back, put breakpoints after the line and in the catch.  Run your code, make sure it goes to the first break point.  If the Dialog displays, then you know what the problem is.  If not, leave it two minutes.  One of the break points will be hit.

 

In my experience, any network activity like you have coded (and especially the read) will be timed out by the OS in 2 minutes. Other people have claimed that this is not the case and like you said the statement never comes back, but closer investigation proved that they were missing the Exception being thrown.

 

It should be a IOException, but please make sure your catch catches all Exceptions. 

 

Let us know how you get on.

Please use plain text.
Super Contributor
lyon819
Posts: 253
Registered: ‎08-19-2010
My Device: BB10, Playbook, 9900, 9800, 9700, 9550, 9530, 9500, 8700.

Re: Fail to transfer several files.

client side issue.

 

always not catch the line.

out = connection.openOutputStream();

 

Does anyone know how to use while (files.hasMoreElements()){ to transfer files??

 

Thank your attention,

 

-Fight with BB10
Please use plain text.
Super Contributor
lyon819
Posts: 253
Registered: ‎08-19-2010
My Device: BB10, Playbook, 9900, 9800, 9700, 9550, 9530, 9500, 8700.

Re: Fail to transfer several files.

Solved it.

 

Thx peter.

 

Final solution.

On both client and server side.

1.Connection accpet and open should put into while loop.

2.Connection close should put into while loop.

3.Stream open and close should put into while loop.

 

After that,

client end could send different files to server end under 2 seconds.

 

Good luck, 

 

Cheers.

 

-Fight with BB10
Please use plain text.