• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

File transer through ServerSocket

 
Ratheesh Narayanan
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I have an application which is having client and server components as console applications. The client has to send a file to the server then the server recieves the file and store it. Now the server has to take another file and send it back to the client.

Can anyone help to find out how can I send send a file back to the client through the ServerSocket I have created at the server.

Thanks in advance..

Ratheesh
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you run through the Sun tutorial on sockets? The Knock Knock Server is a neat example of a client and server holding a conversation with messages going both ways. Your program will send files back and forth instead of simple messages, but the basic idea is the same.

One thing you'll have to make up is some kind of protocol. For example the client might send a header that says "I'm about to send a file. The name is xxxxxx.xxx. The size is nnnnnn", then send the file. The server could read the header, and save the next nnnnnn bytes to file xxxxxx.xxx. It might send a reply "Received file, status OK".

Then the server could repeat the process the other direction and the client could save bytes to a file. Hey, that sounds like a lot of the same code on both ends. Be sure to pull the common code out to common classes rather than copy/paste it to both programs.

Do the Knock Knock tutorial, then see if all this makes sense.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic