aspose file tools
The moose likes Sockets and Internet Protocols and the fly likes Need help to write Client/Server java socket program to transfer files between client/server Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Reply Bookmark "Need help to write Client/Server java socket program to transfer files between client/server " Watch "Need help to write Client/Server java socket program to transfer files between client/server " New topic
Author

Need help to write Client/Server java socket program to transfer files between client/server

Peter Cong
Greenhorn

Joined: Nov 21, 2009
Posts: 10
Hi,
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,

Thanks so much!
peter
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19216

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.


SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Need help to write Client/Server java socket program to transfer files between client/server
 
Similar Threads
how to send a file or photo to clients using sockets??
File transfer in MQ using Java
File trasfer between machines
soap messages using sockets
socket programming using servlet