Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Broadcasting but not getting all the machine in the network

Reply
Thread Tools

Broadcasting but not getting all the machine in the network

 
 
BigZero
Guest
Posts: n/a
 
      04-15-2008
Hello,

here is the code that broadcast the message in Lan, we have around 50
to 60 machines in Lan,
all i m looking for the ip address of up machine in lan
the problem with following code that it not getting all machine ip
address


import java.io.* ;
import java.net.* ;

public class JavaPing {
public static String[] upmachine = new String[100];
public static int i;


public static void main ( String args[ ] ) {

String host = "192.168.1.150" ; // default host put what you
want here
if ( args.length != 0 ) host = args[0] ;

int port = 7 ; // echo service port

String msg = "Test Message" ; // some text
byte[] outbuff = msg.getBytes() ;
int len = outbuff.length ;

long tret ;

DatagramPacket packout , packin ;

try {

System.out.println("\n==> Resolving: " + host + " ..." ) ;
InetAddress iaddr = InetAddress.getByName( host ) ;

packout = new DatagramPacket( outbuff , len , iaddr , port ) ;
// packin = new DatagramPacket( new byte[100] , 100 ) ;
packin = new DatagramPacket( new byte[1024] , 100 ) ;

DatagramSocket sock = new DatagramSocket() ;

// System.out.println("\nLocal Port #:" + sock.getLocalPort() ) ;

sock.send( packout ) ; // send packet

tret = System.currentTimeMillis() ; // get time

System.out.println("\n==> Packet sent to: " + iaddr.toString()+
" Port: " + port ) ;

sock.setSoTimeout(10000) ; // rcv timeout = 10 secs.


while (sock != null)
{
sock.receive( packin ) ; // wait for packet...

tret = System.currentTimeMillis() - tret ; // calc elapsed
time

System.out.println("\ntime elapsed: " + tret + " [ms]" ) ;

//sock.close() ;

System.out.println("\n==> Packet Rcvd from: " +
packin.getAddress()+" Data: " + packin.getLength() + " bytes\n" ) ;

upmachine[i] = (packin.getAddress().toString()).substring(1);
i++;
System.out.println( new String(packin.getData() ).trim() ) ;
}

}

catch ( Exception e ) {

System.out.println( "\n" + e ) ;
// i--;
// upmachine[i] = "\0";
}
System.out.println("The Up Machine in Lan");
for( int j = 0;j < i; j++ )
System.out.println("ip = "+upmachine[j]);

} // end main

} // end Class

this is the code that works fine but getting only few machine
address,plz direct me to do the work


Thanks
VM
 
Reply With Quote
 
 
 
 
Mark Space
Guest
Posts: n/a
 
      04-15-2008
BigZero wrote:

> here is the code that broadcast the message in Lan, we have around 50
> to 60 machines in Lan,
> all i m looking for the ip address of up machine in lan
> the problem with following code that it not getting all machine ip
> address


I'm sorry but I don't see where you put the broadcast address in the
outbound packet. Could you point it out to me?

Do you perhaps mean ping or echo request instead of broadcast?

Can you use your OS "ping" from the command line to verify that the
machines that don't respond are in fact capable of responding? Some
machines firewall off port 7 and won't respond. Some firewall off a lot
more than that, so even the OS "ping" command might not work.

Can you use a different port for testing? Say one above 1024?
 
Reply With Quote
 
 
 
 
BigZero
Guest
Posts: n/a
 
      04-16-2008
i m sorry i just missed the broadcast address,
here the address String host = "192.168.1.150" ; can be set to
192.168.1.255/255.255.255.255 both r working fine,but reply from only
6 machine,
we come to known that these r Linux/Unix machines,so is there any way
i can do it for windows boxes.
we have around 50 to 60 machine including servers






Thanks
Vijay
 
Reply With Quote
 
Mark Space
Guest
Posts: n/a
 
      04-16-2008
BigZero wrote:
> i m sorry i just missed the broadcast address,
> here the address String host = "192.168.1.150" ; can be set to
> 192.168.1.255/255.255.255.255 both r working fine,but reply from only
> 6 machine,


How are both working fine if only 6 machines reply?

Please use correct English. Spelling "are" as "r" doesn't help your
posts get answers.

Did you try ping?
 
Reply With Quote
 
Nigel Wade
Guest
Posts: n/a
 
      04-17-2008
BigZero wrote:

> i m sorry i just missed the broadcast address,
> here the address String host = "192.168.1.150" ; can be set to
> 192.168.1.255/255.255.255.255 both r working fine,but reply from only
> 6 machine,
> we come to known that these r Linux/Unix machines,so is there any way
> i can do it for windows boxes.
> we have around 50 to 60 machine including servers
>


To get a response to the "echo" service that service must be running and
listening [by default] on port 7. It must also not be blocked by a firewall.

If you want all your machines to respond you need to ensure that the above two
criteria are met on every machine. It is a matter of finding out how the OS on
each system provides an "echo" service (if it does so at all) and enabling it,
then allowing it through any firewalls. This is not a Java problem so you
should ask on support groups for the OS/firewalls in question.

You could make it into a Java problem by writing your own echo service in Java.

--
Nigel Wade
 
Reply With Quote
 
BigZero
Guest
Posts: n/a
 
      04-17-2008
ok both means any one can works ,both results the same output ,
that is only 6 machine reply and all 6 machines r Unix/Linux box









Thanks
Vijay
 
Reply With Quote
 
BigZero
Guest
Posts: n/a
 
      04-17-2008
You could make it into a Java problem by writing your own echo service
in Java

what is this ?








Thanks
Vijay
 
Reply With Quote
 
Nigel Wade
Guest
Posts: n/a
 
      04-17-2008
BigZero wrote:

> You could make it into a Java problem by writing your own echo service
> in Java


You need to learn how to quote and get attributions correct.

>
> what is this ?
>


What is what, the echo service? The echo service is what you are trying to use
and, given that you mention it in the comments in your code (it is your code
isn't it?) I presumed you knew that.

--
Nigel Wade
 
Reply With Quote
 
RedGrittyBrick
Guest
Posts: n/a
 
      04-17-2008
BigZero wrote:
> You could make it into a Java problem by writing your own echo service
> in Java
>
> what is this ?
>


It is a service, that you would write, using Java, that listens for
packets arriving at the UDP ECHO port.

Unless you are exactly implementing the UDP echo service according to
the RFCs, it would be better to use a port number that is not
registered. That means one in the range 49151-65535.
http://www.iana.org/assignments/port-numbers

Having written this service you would deploy it on every computer that
you want to be able to monitor.

A service is a program that runs in the background - called a daemon on
Unix, a service on Windows. Usually started automatically.

IIRC you've been given examples, references, APIs and tutorials for this
before.
http://java.sun.com/docs/books/tutor...entServer.html

--
RGB
 
Reply With Quote
 
BigZero
Guest
Posts: n/a
 
      04-17-2008
Ok,Thanks man,







Regards
Vijay
 
Reply With Quote
 
 
 
Reply

Thread Tools

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

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Broadcasting in Java but NOT MulticastSocket CS Java 2 06-28-2010 02:41 AM
Broadcasting in Java but NOT MulticastSocket CS Java 3 06-26-2010 07:54 PM
CHECK BOX MIssing??? connect even if network is not broadcasting BCY1 Wireless Networking 4 12-11-2008 10:00 PM
Windows does not see non-broadcasting wireless network =?Utf-8?B?a21hbm9yZWs=?= Wireless Networking 9 07-26-2007 06:41 PM
Broadcasting all VLANs over a Cisco 1300 AP/Bridges. jetter2@gmail.com Cisco 2 04-25-2007 01:08 PM



Advertisments