M u l t i c a s t L i s t e n e r
J e s s e  P e t e r s o n



MulticastListener is a sample program that listens for X10 status messages broadcast from X10Server.

MulticastListener is run with the standard JDK as follows:

java MulticastListener
This will start the MulticastListener on the default UDP port of 4378 broadcast group 239.6.20.71. The port was chosen at random as the default port for the X10Server. The broadcast group was also chosen at random as the default UDP group. The broadcast group is in the range set aside for private use.

MulticastListener joins the group and then waits for broadcast messages. When it receives a message, it is printed to the screen.

For MulticastListener to do anything useful, an X10Server process must be running on a host on the local network.

Example

Running MulticastListener.

java MulticastListener


Code

The source code for MulticastListener.java can be found in the samples/MulticastListener directory. It is very straight forward. The only function is main. A MulticastSocket is created on the desired port. Then the application joins the broadcast group. Next, the program enters a loop forever. A buffer large enough to hold the current messages is created and the associated DatagramPacket is instantiated. The program calls receive on the MulticastSocket, which blocks until a packet arrives. The the packet arrives, it is converted to a String and printed to System.out.



Copyright © 1999 Jesse Peterson