File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Network Application Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Network Application" Watch "Network Application" New topic
Author

Network Application

Jolix Coder
Greenhorn

Joined: May 01, 2011
Posts: 2
Hi!
I'm making a simple application that should communicate with each other over the internet.
When starting the app, you are asked to be the client or the server. (I allow only 1 client and 1 server)
I know how to work with sockets and I am going to use the "knock knock" protocol.

My question is: how do I know the hostadress of the server when the server could be running on any random PC over the internet.
Thanks in advance!
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18826
    
  40

Jolix Coder wrote:
My question is: how do I know the hostadress of the server when the server could be running on any random PC over the internet.


Simply. You can't. With client/server, the client needs to know how to get to the server -- the server location has to be reachable and can't be random.

If your applications need to find each other, then you have the logic for both sides to go to an agreed upon location to resolve each others' location. It could be at a multicast group and port, which will require that switches route those packets, or it could be at another address and port, which will require some sort of service to resolve the addresses. Even peer to peer environments uses starting locations, to find peers to other peers to eventually, a peer that has what you want.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Jolix Coder
Greenhorn

Joined: May 01, 2011
Posts: 2
Thank you so much for your answer!

Henry Wong wrote:..., which will require some sort of service to resolve the addresses.

Is there some kind of free service out there that just does that?
I have no idea what to google :p
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38784
    
  23
. . . and welcome to the Ranch
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

You want this to work over the internet? Then you should be aware that multicast doesn't work on a network of that size. (You don't want people sending multicasts to millions of hosts, that's just going to plug up the network, so it isn't allowed.) So if your plan requires a network of servers, which can't easily be located, you're going to have to provide that service yourself. Your website would be an ideal place to host that service.

You might also want to investigate how other p2p applications do that.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Network Application