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..
SCJP 1.4 & SCBCD 1.5
posted 9 years ago
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.
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi