aspose file tools*
The moose likes Java in General and the fly likes Transfer Multiple File problems via socket Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Reply locked New topic
Author

Transfer Multiple File problems via socket

Tan Kok Lim
Greenhorn

Joined: Oct 23, 2012
Posts: 7
There is not problem in client side, no matter my client side sending how many but it could only able transfer one file to server side

at last it returns to this error:

Exception in thread "main" java.net.SocketException: Socket is closed
at java.net.Socket.getOutputStream(Unknown Source)
at clientSend.com.ClientSend.main(ClientSend.java:72)


Client Side




Server side





My problem is here how can i detect/scan number of file received from client by modifying server side coding then i can used to performed looping to write output file. Appreciate any help.
nir sharma
Ranch Hand

Joined: Sep 11, 2012
Posts: 72

can you put your code in code tag its difficult to understand.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39885
    
  28
Welcome to the Ranch
Since you are new, I shall add code tags and you can see how much better it looks Unfortunately I had to get rid of lots of blank lines and lines too long. You are mixing tabs and spaces in your indenting; only ever use spaces.
When do you suffer that Exception? Before you open the socket or afterwards? Have you closed the socket anywhere?
Tan Kok Lim
Greenhorn

Joined: Oct 23, 2012
Posts: 7
okay....thanks to admin by help me putting code tag.

Anyone can help to solve here problem,,,,,,thanks

To Campbell Ritchie,

I can pass through the first file processing but I'll be stop at second file processing when running in the for loop process at client
the problem i found at os=clientData.getOutputStream() here where it will be stuck at second times in loop process.

I've modified the above code.

Richard Tookey
Ranch Hand

Joined: Aug 27, 2012
Posts: 1084
    
  10

I don't understand why you are writing just one file per connection in the client and trying to read two files per connection in the server. Did you mean to do that or did you more logically want a new accept() for each file?
nir sharma
Ranch Hand

Joined: Sep 11, 2012
Posts: 72

Dont make the changes in your original code, rather post changes separately in a new post.

in your server code, you have written the below code twice, is it intentional?



closes the socket.

lastly, in your server code, you are expecting a new connection for every file need to be transferred while in client code you are making only one connection, thats why only one file is transferred because after that server is waiting for the new connection.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39885
    
  28
nir sharma wrote:Dont make the changes in your original code, rather post changes separately in a new post. . . .
Agree. It can make responses look like nonsense if the previous post is changed.



closes the socket. . . .
I thought there would be something like that: well done finding it
Tan Kok Lim
Greenhorn

Joined: Oct 23, 2012
Posts: 7
Thanks for all your previous guide,

This time I've success to transfer a bunch of file from one directory to another directory but the the server's connection will be reset each time transfer is done.

the server will simply returns this message:

Starting...
Starting...
Starting...
Starting...
File Size =1716298
File Size =1649677
File Size =2555655
Starting...
Exception in thread "main" java.lang.IllegalArgumentException: Illegal Capacity: -1
at java.util.ArrayList.<init>(Unknown Source)
at ServerSocket.com.ServerRun.main(ServerRun.java:51)


Here below Is my code

Server Side:




Client Sides




My problem here how can I ensure continues running of server without reset each time transfer is completed? Thanks to any mindful helps.

Tan Kok Lim
Greenhorn

Joined: Oct 23, 2012
Posts: 7
okay, done i've settled by putting flag = false when it encountered number of file is reach to index array less one before max.
let said total file from client send is digit 2 but index 0 will stored digit 1, index 1 stored digit 2, while index 3 stored in nothings.



Here is my modified server's code:



Another Question is here because my server will be stop running after one time transfer is done, I want to keep it running, How can I do it? I mean how can i keep
clientSocket = serverSocket.accept() to open the port for running and waiting to received request from client after one time send is done.

Appreciate thankful to any helps.
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Tan Kok Lim wrote:
Another Question is here because my server will be stop running after one time transfer is done, I want to keep it running, How can I do it? I mean how can i keep
clientSocket = serverSocket.accept() to open the port for running and waiting to received request from client after one time send is done.


You've heard of loops, right?
Tan Kok Lim
Greenhorn

Joined: Oct 23, 2012
Posts: 7
After Few times attempts, I've succeeded in my code which can be working on client side in sending and server won't stop stop executing after each time received file form client.

Server Side



Client Side




 
jQuery in Action, 2nd edition
 
subject: Transfer Multiple File problems via socket