views:

44

answers:

2

How to communicate by (socket, Thread) to transfer file?

+1  A: 

Similar solution is posted on following links. You can browse these for your answer:
http://forums.sun.com/thread.jspa?threadID=5372011
http://www.rgagnon.com/javadetails/java-0542.html

You can go through these tutorials and examples for understanding sockets.
http://java.sun.com/developer/onlineTraining/Programming/BasicJava2/socket.html
http://download.oracle.com/docs/cd/E17409_01/javase/tutorial/networking/sockets/

These should definitely help.

YoK
A: 

Your question is pretty vague and broad, so naturally my response is vague and broad.

Threads exist within the same process, running on the same JVM, and share memory and resources. They can share access to resources. This will help you get started.

Since you're interested in transferring a file, I'll assume you want to transfer that file between processes in a logically distributed application (one that is split across JVMs that may or may not be running on the same physical machine). In that case, sockets would be more useful to you.

Sockets are a low level way of approaching this problem. This will help you get started with sockets.

There are other alternatives to sockets, such as Java RMI, JEE Web Services, CORBA, and Java Messaging Service, but whether they're appropriate depends on what you're ultimately trying to achieve.

For something simple, sockets are likely to be adequate, but be prepared for a socket-based approach to become trickier as you attempt more complicated functionality

chrisbunney