Results 1 to 3 of 3
  1. #1
    javastuden's Avatar
    javastuden is offline Senior Member
    Join Date
    Nov 2009
    Posts
    180
    Rep Power
    9

    Default send udp packet to ip address

    hi all ,

    i need to send packet to two ipaddress, no broadcast or multicast,( it can be access in multiple computers).

    my send pgm is
    Java Code:
    private String senddata(byte[] bytearray) {
            DatagramSocket serverSocket = null;
            try {
                serverSocket = new DatagramSocket();
                serverSocket.setReuseAddress(true);
                byte[] receiveData = new byte[65508];
                byte[] sendData = new byte[65508];
                serverSocket.setSoTimeout(50);
                sendData = bytearray;
                InetAddress IPAddress = InetAddress.getByName("100.160.10.216");
                InetAddress IPAddress2 = InetAddress.getByName("100.160.10.218");            
                DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, IPAddress, 4002);
                serverSocket.send(sendPacket);            
                serverSocket.close();
                return "true";
            } catch (SocketException ex) {
                System.err.println("Exception SocketException senddata " + Integer.toString(4002) + ex.getMessage());
            } catch (IOException ex) {
                System.err.println("Exception IOException senddata " + Integer.toString(4002) + ex.getMessage());
            } finally {
                serverSocket.close();
            }
            return null;
        }
    can i send to these ip address in same time of in multicast can i do the same, if so do there any thing i need to do in ip address of client computer and in my computer.

    please help me

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,166
    Rep Power
    12

    Default Re: send udp packet to ip address

    You can either send them serially or possibly "simultaneously" using threads. I put that in quotes because eventually, the interface will be sending
    them one after the other unless you are sending them out different interfaces.

    Multicast does not send out multiple packets. You would simply send out one packet to a multicast address where the message gets duplicated and transmitted
    at one or many points along the path. The whole point of it is to conserve bandwidth when dealing with multiple destinations. This also presumes that multicast
    is enabled on the network.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  3. #3
    javastuden's Avatar
    javastuden is offline Senior Member
    Join Date
    Nov 2009
    Posts
    180
    Rep Power
    9

    Default Re: send udp packet to ip address

    Thanks jim, thanks for your reply.

    let me check with threads, if its not get success, i'll try with serially.

    thanks .

Similar Threads

  1. packet finder
    By chopficaro in forum Advanced Java
    Replies: 2
    Last Post: 04-28-2014, 11:21 AM
  2. Replies: 10
    Last Post: 06-06-2010, 06:49 PM
  3. Trying to send UDP discovery packet
    By JohnST in forum New To Java
    Replies: 1
    Last Post: 12-26-2009, 07:32 PM
  4. Replies: 2
    Last Post: 12-22-2008, 03:05 AM
  5. Send Datagram packet to root server
    By jammin in forum Networking
    Replies: 1
    Last Post: 11-15-2008, 12:23 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
  •