Win a copy of Micro Frontends in Action this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

File trasfer between machines

 
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.
 
Sheriff
Posts: 22004
107
Eclipse IDE Spring VI Editor Chrome Java Ubuntu 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
Posts: 22004
107
Eclipse IDE Spring VI Editor Chrome Java Ubuntu 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
Posts: 22004
107
Eclipse IDE Spring VI Editor Chrome Java Ubuntu 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.
 
We cannot change unless we survive, but we will not survive unless we change. Evolving tiny ad:
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic