Go Back   Garayed.com > Java
Reply
 
LinkBack Thread Tools Search this Thread Display Modes

Detecting server on lan
  #1 (permalink)  
Old 07-02-2009, 03:30 AM
Ken T.
 
Posts: n/a
Default Detecting server on lan

I would like to have the client detect a server on a lan. So there will
be some 30 clients on the same lan as a single server and when they start
I want them to be able to find the server and automatically connect to it
for using RMI.

My idea was to have them send out a UDP packet to the broadcast address
and then have the server respond saying, "Here I am!", but I'm having
difficulty figuring out how to send a UDP packet to the broadcast address
of the lan.

I tried just sending it to "255.255.255.255", but this didn't work. Is
there a way to detect the broadcast address? Is there a way to send a
packet to it? Is there a simpler way to do what I'm trying to do?

Thanks.



--
Ken T.
http://www.electricsenator.net

As we enjoy great advantages from the inventions of others, we should
be glad of an opportunity to serve others by any invention of ours.
-- Benjamin Franklin
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Re: Detecting server on lan
  #2 (permalink)  
Old 07-02-2009, 04:28 AM
Knute Johnson
 
Posts: n/a
Default Re: Detecting server on lan

Ken T. wrote:
> I would like to have the client detect a server on a lan. So there will
> be some 30 clients on the same lan as a single server and when they start
> I want them to be able to find the server and automatically connect to it
> for using RMI.
>
> My idea was to have them send out a UDP packet to the broadcast address
> and then have the server respond saying, "Here I am!", but I'm having
> difficulty figuring out how to send a UDP packet to the broadcast address
> of the lan.
>
> I tried just sending it to "255.255.255.255", but this didn't work. Is
> there a way to detect the broadcast address? Is there a way to send a
> packet to it? Is there a simpler way to do what I'm trying to do?
>
> Thanks.


You can't just try to connect to the server?

--

Knute Johnson
email s/nospam/knute2009/

--
Posted via NewsDemon.com - Premium Uncensored Newsgroup Service
------->>>>>>http://www.NewsDemon.com<<<<<<------
Unlimited Access, Anonymous Accounts, Uncensored Broadband Access
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Re: Detecting server on lan
  #3 (permalink)  
Old 07-02-2009, 06:29 AM
Roedy Green
 
Posts: n/a
Default Re: Detecting server on lan

On 02 Jul 2009 03:30:34 GMT, "Ken T." <nowhere@home.com> wrote, quoted
or indirectly quoted someone who said :

> Is there a simpler way to do what I'm trying to do?


I would implement some trivial transaction on the server, e.g.
what version are you? are you alive?

Then just send that as a GET HTTP packet.
--
Roedy Green Canadian Mind Products
http://mindprod.com

"Deer hunting would be fine sport, if only the deer had guns."
~ William S. Gilbert of Gilbert and Sullivan
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Re: Detecting server on lan
  #4 (permalink)  
Old 07-02-2009, 07:01 AM
Ken T.
 
Posts: n/a
Default Re: Detecting server on lan

On Wed, 01 Jul 2009 21:28:57 -0700, Knute Johnson wrote:

> Ken T. wrote:
>> I would like to have the client detect a server on a lan. So there
>> will be some 30 clients on the same lan as a single server and when
>> they start I want them to be able to find the server and automatically
>> connect to it for using RMI.
>>
>> My idea was to have them send out a UDP packet to the broadcast address
>> and then have the server respond saying, "Here I am!", but I'm having
>> difficulty figuring out how to send a UDP packet to the broadcast
>> address of the lan.
>>
>> I tried just sending it to "255.255.255.255", but this didn't work. Is
>> there a way to detect the broadcast address? Is there a way to send a
>> packet to it? Is there a simpler way to do what I'm trying to do?
>>
>> Thanks.

>
> You can't just try to connect to the server?


That's the thing.. I don't know its IP address. I want to detect it.




--
Ken T.
http://www.electricsenator.net

The only two things that are infinite in size are the universe and
human stupidity. And I'm not completely sure about the universe.
-- Albert Einstein
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Re: Detecting server on lan
  #5 (permalink)  
Old 07-02-2009, 07:04 AM
Ken T.
 
Posts: n/a
Default Re: Detecting server on lan

On Wed, 01 Jul 2009 23:29:23 -0700, Roedy Green wrote:

> On 02 Jul 2009 03:30:34 GMT, "Ken T." <nowhere@home.com> wrote, quoted
> or indirectly quoted someone who said :
>
>> Is there a simpler way to do what I'm trying to do?

>
> I would implement some trivial transaction on the server, e.g. what
> version are you? are you alive?
>
> Then just send that as a GET HTTP packet.


OK, this isn't a web server. This is a server I'm writing for part of
the program. I won't know what machine it is running on. So what I'm
trying to do is to detect what the ip address of the server is.

The idea was that a client would scream out

"Marco"

on a broadcast address, and the server would answer,

"Polo"

by sending a UDP packet back to the client, thereby giving the client its
IP address.

If there is a better way to do this, please let me know.

Thanks.

--
Ken T.
http://www.electricsenator.net

The optimist thinks this is the best of all possible worlds. The
pessimist fears it is true.
-- Robert Oppenheimer
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Re: Detecting server on lan
  #6 (permalink)  
Old 07-02-2009, 07:59 AM
Steven Simpson
 
Posts: n/a
Default Re: Detecting server on lan

Ken T. wrote:
> I would like to have the client detect a server on a lan. [...]
>
> My idea was to have them send out a UDP packet to the broadcast address
> and then have the server respond saying, "Here I am!", but I'm having
> difficulty figuring out how to send a UDP packet to the broadcast address
> of the lan.


I've not tried this, but I'd look at:

<http://java.sun.com/javase/6/docs/api/java/net/InterfaceAddress.html#getBroadcast%28%29>

Get the InterfaceAddress for the NetworkInterface connected to the LAN
to want to broadcast on. If you have no criteria for choosing one, you
could try them all.

--
ss at comp dot lancs dot ac dot uk
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Re: Detecting server on lan
  #7 (permalink)  
Old 07-02-2009, 10:59 AM
Nigel Wade
 
Posts: n/a
Default Re: Detecting server on lan

Ken T. wrote:

> I would like to have the client detect a server on a lan. So there will
> be some 30 clients on the same lan as a single server and when they start
> I want them to be able to find the server and automatically connect to it
> for using RMI.
>
> My idea was to have them send out a UDP packet to the broadcast address
> and then have the server respond saying, "Here I am!", but I'm having
> difficulty figuring out how to send a UDP packet to the broadcast address
> of the lan.
>
> I tried just sending it to "255.255.255.255", but this didn't work. Is
> there a way to detect the broadcast address? Is there a way to send a
> packet to it? Is there a simpler way to do what I'm trying to do?


Use the rmiregistry. That's what it's for.

--
Nigel Wade
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Re: Detecting server on lan
  #8 (permalink)  
Old 07-02-2009, 11:08 AM
John B. Matthews
 
Posts: n/a
Default Re: Detecting server on lan

In article <4a4c5b40$0$24741$ec3e2dad@news.usenetmonster.com> ,
"Ken T." <nowhere@home.com> wrote:

> On Wed, 01 Jul 2009 21:28:57 -0700, Knute Johnson wrote:
>
> > Ken T. wrote:
> >> I would like to have the client detect a server on a lan. So there
> >> will be some 30 clients on the same lan as a single server and when
> >> they start I want them to be able to find the server and automatically
> >> connect to it for using RMI.
> >>
> >> My idea was to have them send out a UDP packet to the broadcast address
> >> and then have the server respond saying, "Here I am!", but I'm having
> >> difficulty figuring out how to send a UDP packet to the broadcast
> >> address of the lan.
> >>
> >> I tried just sending it to "255.255.255.255", but this didn't work. Is
> >> there a way to detect the broadcast address? Is there a way to send a
> >> packet to it? Is there a simpler way to do what I'm trying to do?

> >
> > You can't just try to connect to the server?

>
> That's the thing.. I don't know its IP address. I want to detect it.


You might look into zeroconf/bonjour:

<http://en.wikipedia.org/wiki/Multicast_DNS>

--
John B. Matthews
trashgod at gmail dot com
<http://sites.google.com/site/drjohnbmatthews>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Re: Detecting server on lan
  #9 (permalink)  
Old 07-02-2009, 04:09 PM
Knute Johnson
 
Posts: n/a
Default Re: Detecting server on lan

Ken T. wrote:
> On Wed, 01 Jul 2009 21:28:57 -0700, Knute Johnson wrote:
>
>> Ken T. wrote:
>>> I would like to have the client detect a server on a lan. So there
>>> will be some 30 clients on the same lan as a single server and when
>>> they start I want them to be able to find the server and automatically
>>> connect to it for using RMI.
>>>
>>> My idea was to have them send out a UDP packet to the broadcast address
>>> and then have the server respond saying, "Here I am!", but I'm having
>>> difficulty figuring out how to send a UDP packet to the broadcast
>>> address of the lan.
>>>
>>> I tried just sending it to "255.255.255.255", but this didn't work. Is
>>> there a way to detect the broadcast address? Is there a way to send a
>>> packet to it? Is there a simpler way to do what I'm trying to do?
>>>
>>> Thanks.

>> You can't just try to connect to the server?

>
> That's the thing.. I don't know its IP address. I want to detect it.
>
>
>
>


OK, I understand what you are asking now. The UDP packet idea sounds
pretty simple. Just have the server broadcast to a specific address and
port with its IP address. The clients can read the UDP packets and
connect to the sent address. There is a range for multicast addresses,
take a look at the class MulticastSocket. It has all the details and if
you know how to do UDP datagrams in Java you should be good to go.

--

Knute Johnson
email s/nospam/knute2009/

--
Posted via NewsDemon.com - Premium Uncensored Newsgroup Service
------->>>>>>http://www.NewsDemon.com<<<<<<------
Unlimited Access, Anonymous Accounts, Uncensored Broadband Access
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Re: Detecting server on lan
  #10 (permalink)  
Old 07-02-2009, 09:32 PM
Ken T.
 
Posts: n/a
Default Re: Detecting server on lan

On Thu, 02 Jul 2009 11:59:11 +0100, Nigel Wade wrote:

> Ken T. wrote:
>
>> I would like to have the client detect a server on a lan. So there
>> will be some 30 clients on the same lan as a single server and when
>> they start I want them to be able to find the server and automatically
>> connect to it for using RMI.
>>
>> My idea was to have them send out a UDP packet to the broadcast address
>> and then have the server respond saying, "Here I am!", but I'm having
>> difficulty figuring out how to send a UDP packet to the broadcast
>> address of the lan.
>>
>> I tried just sending it to "255.255.255.255", but this didn't work. Is
>> there a way to detect the broadcast address? Is there a way to send a
>> packet to it? Is there a simpler way to do what I'm trying to do?

>
> Use the rmiregistry. That's what it's for.


That just pushes the problem one more step away...

How do I find the rmiregistry?

--
Ken T.
http://www.electricsenator.net

There are 10 types of people in this world: those who understand
binary and those who don't.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 12:08 AM.


Powered by vBulletin® Version 3.5.8
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0
| Home | FAQ | Members List | Calendar | Today's Posts | Search | New Posts |