Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

File trasfer between machines

 
joseph prabhu
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello

i need java program to transfer files between two machine.

As a first step i get the list of files in the machine(source).
i create a socket class object like this



it gives following excetion.

java.net.ConnectException: Connection refused: connect
java.net.ConnectException: Connection refused: connect

what is the error in Socket class . please help me.
 
Rob Spoor
Sheriff
Pie
Posts: 20550
57
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The other PC should have a server socket listening on that same port, or of course it will fail.

Why not use a known protocol like SMB (also known as Windows sharing, Samba is the Unix / Linux implementation) or FTP?
 
joseph prabhu
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Rob Prime:
The other PC should have a server socket listening on that same port, or of course it will fail.

Why not use a known protocol like SMB (also known as Windows sharing, Samba is the Unix / Linux implementation) or FTP?


hello

i create the ServerSocket class object of constructor


it gives the exception called

java.net.BindException: Cannot assign requested address: JVM_Bind
java.net.BindException: Cannot assign requested address: JVM_Bind

but it does not give the exception for other 2 constructors
 
Rob Spoor
Sheriff
Pie
Posts: 20550
57
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The third parameter to the ServerSocket constructor should be the IP address or hostname of the server itself, in case you have multiple IP addresses or hostnames. In your case you probably won't need that so you can just omit it.

That parameter does NOT indicate the client - servers shouldn't care about who their clients are*, as long as they follow the protocol.


And don't forget to start the server before starting the client


* Of course it's possible to block IP addresses because of security, but that's at a higher level.
 
joseph prabhu
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Rob Prime:
The third parameter to the ServerSocket constructor should be the IP address or hostname of the server itself, in case you have multiple IP addresses or hostnames. In your case you probably won't need that so you can just omit it.

That parameter does NOT indicate the client - servers shouldn't care about who their clients are*, as long as they follow the protocol.


And don't forget to start the server before starting the client


* Of course it's possible to block IP addresses because of security, but that's at a higher level.


i am going to develop the one program to copy the files between the machines

not as client or server program. is it correct.
 
Rob Spoor
Sheriff
Pie
Posts: 20550
57
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, you started using Sockets, so you need some server (ServerSocket) to connect to. That makes this a client-server solution.

Like I asked before,
Originally posted by Rob Prime:
Why not use a known protocol like SMB (also known as Windows sharing, Samba is the Unix / Linux implementation) or FTP?

You can then use the java.io package. You will need a third party library for the FTP part, but Apache Commons Net and JvFTP are great for that.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic