I want to write a client/server socket java program to simulate FTP to transfer file between client and server.
Basically, the program performs 3 commands: put: upload files to server, get: downloads files from server,change:change files name resides in server.
the program is running on two local machine(client and sever) by command line input.
Appreciate any help or resource,
You will need to define a protocol for this: the client sends a request, and the server sends a response.
If you don't mind limiting the protocol to Java you could send objects, and wrap the Socket's streams into ObjectInputStream and ObjectOutputStream. You then send a Request object, and wait until the server sends a Response object. You can use one interface for Request with multiple implementations (one for each request type), and one interface for Response with multiple implementations (one for each response type).
If you want to make it more general you will need to go through a bit more trouble. A very simple example for download:
- "download <file>" is sent to the server
- the server sends back the number of bytes to send, followed by the file's bytes. The number is used to determine how many bytes to read, since the stream will not be closed afterwards; you will reuse it for other requests.