aspose file tools
The moose likes Sockets and Internet Protocols and the fly likes Sending files from server to client... Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Reply Bookmark "Sending files from server to client..." Watch "Sending files from server to client..." New topic
Author

Sending files from server to client...

Steven Wolf
Greenhorn

Joined: Jun 17, 2003
Posts: 2
We want to transfer a file from a server socket to a client socket (a file, not a string).
We are students and work for a school-project.
We wrote the following Code, but it doesn't work properly. We work with Threads. The file exists, so this can't be the problem.

Client:

Server:

Thank You
Steven & Adrian
[ June 17, 2003: Message edited by: Steven Wolf ]
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
Hi Steven,
Welcome to JavaRanch. What exactly do you want to do here? Do you want to create a copy of the file sent from the server onto the client machine? All it appears that you are doing now is creating a String (you need to change nwe to new) that grows by ten bytes on each read and then doing nothing with the String.


Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
Steven Wolf
Greenhorn

Joined: Jun 17, 2003
Posts: 2
Hi Michael
What we want to do is: The client should be able to find a specific file on the server and download a copy of it.
The nwe was a misstake
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
Originally posted by Steven Wolf:
Hi Michael
What we want to do is: The client should be able to find a specific file on the server and download a copy of it.
The nwe was a misstake

In that case, you will need to open both input and output streams on both ends of the socket for communication. It is usually best for the server to start the conversation and it is genereally best to get the server up and running before starting the client code. You can test the server using telnet. The basic scenario would be:
  • Client connects to Server
  • Server sends greeting banner to Client
  • Client acknowledges greeting and sends request for file
  • Sever receives Client request and tries to locate file
  • Server sends status of request to Client (file found or not)
  • Client acknowledges status receipt and if file was found sends ready for transfer notice to Server
  • Server sends the file and closes the connection
  • Client receives the file and stores it locally

  •  
    I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
     
    subject: Sending files from server to client...
     
    Similar Threads
    client-server file exchange
    Sending a file over socket
    moving files over the network
    Write a String to ByteArrayOutputStream
    Pblm with JAR/InputStream