Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to sent file to client by socket?  RSS feed

 
Jim Wang
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I'm using tomcat passing servlet page. There has a function let user download file from server. Since my client don't want to see the 'save as' window and don't want user change file name, I have to make this thing work as a background job. I think I may get this from socket. Since I never use socket before, I really need some help about the idea of how to do it.
Thanks.
Jim
 
Laudney Ren
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, using Socket really requires some knowledge. A brief procedure is described here:
Server creates a ServerSocket and ueses accept(0 to listen on a specific port. Accept() returns the established Socket. Call Socket 's getOutputStream and write to the stream.
Client calls Socket's getInputStream and reads from the stream.
Well, I describe the process quite briefly here. For authoritive information about Java net programming, refer to Elliotte Harold's Java Network Programming or go to his website http://metalab.unc.edu/javafaq
 
Jim Wang
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Laudney,
I read some documents about socket and it same as you said. I got a question here, if I'm going to send a file to client by socket, is that mean I also need to put a application on client side to create the connection for download file?
Jim
 
Laudney Ren
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, sometimes the client can also be the server.
Method 1: on the client side, establish a socke to the server.
Method 1: make your client a server, listen on a specific port and the server (now a client) establish the socket (or connetion) actively.
Anyway, you need coding on both sides.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!