Win a copy of Pragmatic AI this week in the Artificial Intelligence forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

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

 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 21426
94
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!