The moose likes Sockets and Internet Protocols and the fly likes How to sent file to client by socket? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Reply Bookmark "How to sent file to client by socket?" Watch "How to sent file to client by socket?" New topic
Author

How to sent file to client by socket?

Jim Wang
Ranch Hand

Joined: Oct 04, 2001
Posts: 41
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

Joined: Jan 06, 2002
Posts: 111
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


" Veni, vidi, vici "<br />" I came, I saw, I conquered "
Jim Wang
Ranch Hand

Joined: Oct 04, 2001
Posts: 41
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

Joined: Jan 06, 2002
Posts: 111
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.
 
 
subject: How to sent file to client by socket?
 
Threads others viewed
Session
SSL Communication between Java and VC++
Reading file from a client
Delete file from client system using Jsp / servlet
Signed applet download
WebSphere development made easy
without the weight of IBM tools
http://www.myeclipseide.com