| 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 ServerServer sends greeting banner to ClientClient acknowledges greeting and sends request for fileSever receives Client request and tries to locate fileServer 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 ServerServer sends the file and closes the connectionClient receives the file and stores it locally
|
 |
 |
|
|
subject: Sending files from server to client...
|
|
|