Results 1 to 2 of 2
  1. #1
    Alpha is offline Member
    Join Date
    May 2007
    Rep Power

    Default How to brodcast a message in the LAN

    I want to broadcast a message to LAN. Is this possible with Java?

  2. #2
    levent Guest


    You can do this with DatagramSocket.

    You can use the socket like this:

    Java Code:
    public class MainClass {
      public static void main(String[] args) {
        try {
          String data = "data in UDP";
          byte [] buffer = data.getBytes();
          DatagramPacket packet = new DatagramPacket(buffer, buffer.length,
                    new InetSocketAddress("localhost", 5002));
          DatagramSocket socket = new DatagramSocket(5003);
          System.out.println("Sending a packet...");
        }catch(IOException e)
    And for broadcasting your message, you should enable SO_BROADCAST using setBroadcast(boolean on) method.
    Last edited by levent; 05-20-2007 at 05:12 PM.

Similar Threads

  1. One Producer - Many Consumers - Same Message
    By zhackwyatt in forum Threads and Synchronization
    Replies: 1
    Last Post: 04-23-2008, 09:27 PM
  2. Please wail Message in jsp
    By in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 04-02-2008, 01:29 PM
  3. simulate message box
    By pablitohh in forum New To Java
    Replies: 1
    Last Post: 12-05-2007, 05:52 PM
  4. About bean:message
    By yuchuang in forum Web Frameworks
    Replies: 1
    Last Post: 05-03-2007, 05:50 PM
  5. error message on jsp
    By sandor in forum Web Frameworks
    Replies: 1
    Last Post: 04-11-2007, 03:10 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts