• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Transfer file from a client to server

 
Java Networking
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wrote a client server program where client send request and reciev reply and the server makes connection for each client and tehn echoes the client request.
I want to modify this program too send a file from client to server.
How can i do that any help will be appreciated.
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi J.N.,
Welcome to JavaRanch!
We ain't got too many rules round these parts, but we do have our naming policy. Your display name can't be an obvious fake, like your'n. Thank you kindly for hot-footin' it over here to fix yours up!
Now, on to your question.
If you've written the echo server you've described, I'm not sure why you'd have a problem with transferring a file. Just open the file and spit all the data through the connection. Of course, the server has to be waiting for it. To make life easier, you might want to send the file name and file size first, and have the server be expecting that, too.
Be sure to use InputStreams and OuputStreams, not Readers and Writers, to transfer the data, or your program won't work for non-textual files.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Robert Martin has been writing a series about sending compile jobs to a server - send source and get back listings and class files. It has some neat ideas about wrapping files in objects for socket transfer. See if somebody has a stack of Software Development magazines, or try http://www.sdmagazine.com/columnists/martin/ online. His ObjectMentor.com site is not responding right now, but if it comes back the articles are there, too.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic