File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Sockets and Internet Protocols and the fly likes send files over the socket Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "send files over the socket" Watch "send files over the socket" New topic
Author

send files over the socket

Bobes Calin
Greenhorn

Joined: Nov 13, 2008
Posts: 14
I have a litle problem (i think) on my client server application. The aplication sends one file and not all that i give it to it.

here is the code for the server....



and for the client....



Can anybody show me how to send all the files? Thank you!

Calin
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24166
    
  30

Looks like your client should send all the files, but your server will only read one. "receiveFileFromClient()" should be called in a loop, right?


[Jess in Action][AskingGoodQuestions]
Bobes Calin
Greenhorn

Joined: Nov 13, 2008
Posts: 14
yes the server reads only the fisrt file. How can i do the loop? on what criteria?

Thank you!

Calin
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24166
    
  30

Maybe the client could send the number of files to expect first, and then you could just use a "for" loop.
Bobes Calin
Greenhorn

Joined: Nov 13, 2008
Posts: 14
I tried to send the number of files that are in the File[] array

in the client sendFileToServer()



and the server receiveFileFromClient()



but hte same thing, only the first file is send.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24166
    
  30

You want to read the file count from the socket only once, and store it in a variable, and then use that variable in the for loop. If you do this:



then the count gets changed to some random value each time through the loop, and that isn't good!
Bobes Calin
Greenhorn

Joined: Nov 13, 2008
Posts: 14
yes you are right with the count.



i put it out from the loop and initialized with a with an int value on the server



but the same thing only one file is copied
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: send files over the socket
 
Similar Threads
No main class
problem with java.net.SocketException at client site
Transferring file name then file data over socket
When to use flush() in Java?
Java net BindException:Address already in use: JVM_Bind