Results 1 to 2 of 2
  1. #1
    JohnST is offline Member
    Join Date
    Dec 2009
    Posts
    20
    Rep Power
    0

    Question Trying to send UDP discovery packet

    I've looked everywhere online and have gone through tutorials still with no luck. I realize there is something wrong with IPAddress in the datagram packet. What I can't figure out either is how I can change the socketserver to listen on local port 31337. I'm trying to do the Java equivalent of this I REMOVED THE LINK display the ipaddress of the controller. I realize I still have a lot to learn. I just want to work on something more appealing at the moment.

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

    class UDPc4 {
    public static void main(String args[]) throws Exception{

    DatagramSocket clientSocket = new DatagramSocket();

    InetAddress IPAddress = InetAddress.getByName("host");
    byte[] sendData = new byte[512];
    byte[] receiveData = new byte[512];

    String message = "M-SEARCH * HTTP/1.1\r\n"
    + "HOST: 239.255.255.250:1900\r\n"
    + "MAN: \"ssdp:discover\"\r\n"
    + "MX: 5\r\n"
    + "ST: c4:director\r\n"
    + "\r\n";

    sendData = message.getBytes();

    DatagramPacket packet =
    new DatagramPacket(sendData, sendData.length, IPAddress, 1900);


    clientSocket.send(packet);


    packet = new DatagramPacket(receiveData, receiveData.length);
    clientSocket.receive(packet);
    String received = new String(packet.getData(), 0,packet.getLength());
    System.out.println("Controller found " + received);
    }
    }

  2. #2
    JohnST is offline Member
    Join Date
    Dec 2009
    Posts
    20
    Rep Power
    0

    Default

    Ok I am getting a response. How do I get the IP address?

    Java Code:
    import java.io.*;
    import java.net.*;
    
    class UDPc4 {
     public static void main(String args[]) throws Exception
     
     {
     DatagramSocket clientSocket = new DatagramSocket(21557);
     InetAddress group = InetAddress.getByName("239.255.255.250");
    
    
     byte[] sendData = new byte[0];
     byte[] receiveData = new byte[128];
     String sentance = "M-SEARCH * HTTP/1.1\r\n"
     + "HOST: 239.255.255.250:1900\r\n"
     + "MAN: \"ssdp:discover\"\r\n"
     + "MX: 5\r\n"
     + "ST: c4:director\r\n"
     + "\r\n";
         
     sendData = sentance.getBytes();
    
     DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, group, 1900);
    
     clientSocket.send(sendPacket);
     System.out.println("sent packet...");
     DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length);
    
     clientSocket.receive(receivePacket);
    
     String controllerResponse = new String(receivePacket.getData());
     
     System.out.println("response:\n" +controllerResponse);
     clientSocket.close();
     }
    
    }

Similar Threads

  1. How to identify packet type?
    By priya deshpande in forum Networking
    Replies: 0
    Last Post: 10-11-2009, 06:40 AM
  2. Replies: 2
    Last Post: 12-22-2008, 03:05 AM
  3. Send Datagram packet to root server
    By jammin in forum Networking
    Replies: 1
    Last Post: 11-15-2008, 12:23 AM
  4. fake ARP broadcast packet
    By junkredish in forum Networking
    Replies: 0
    Last Post: 09-06-2008, 06:01 PM
  5. Bible-Discovery 2.1
    By JavaBean in forum Java Software
    Replies: 0
    Last Post: 10-25-2007, 04:19 PM

Posting Permissions

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