Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Java (http://www.velocityreviews.com/forums/f30-java.html)
-   -   Broadcasting but not getting all the machine in the network (http://www.velocityreviews.com/forums/t605642-broadcasting-but-not-getting-all-the-machine-in-the-network.html)

BigZero 04-15-2008 05:06 AM

Broadcasting but not getting all the machine in the network
 
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

Mark Space 04-15-2008 04:52 PM

Re: Broadcasting but not getting all the machine in the network
 
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?

BigZero 04-16-2008 07:24 AM

Re: Broadcasting but not getting all the machine in the network
 
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

Mark Space 04-16-2008 05:54 PM

Re: Broadcasting but not getting all the machine in the network
 
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?

Nigel Wade 04-17-2008 08:18 AM

Re: Broadcasting but not getting all the machine in the network
 
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

BigZero 04-17-2008 12:19 PM

Re: Broadcasting but not getting all the machine in the network
 
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

BigZero 04-17-2008 12:19 PM

Re: Broadcasting but not getting all the machine in the network
 
You could make it into a Java problem by writing your own echo service
in Java

what is this ?








Thanks
Vijay

Nigel Wade 04-17-2008 01:16 PM

Re: Broadcasting but not getting all the machine in the network
 
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

RedGrittyBrick 04-17-2008 01:25 PM

Re: Broadcasting but not getting all the machine in the network
 
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

BigZero 04-17-2008 01:27 PM

Re: Broadcasting but not getting all the machine in the network
 
Ok,Thanks man,







Regards
Vijay


All times are GMT. The time now is 04:51 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.