• Post Reply Bookmark Topic Watch Topic
  • New Topic

Sending files from server to client...

 
Steven Wolf
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Steven Wolf
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

  •  
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!