Results 1 to 2 of 2
- 12-25-2009, 01:15 AM #1
Member
- Join Date
- Dec 2009
- Posts
- 20
- Rep Power
- 0
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);
}
}
- 12-26-2009, 07:32 PM #2
Member
- Join Date
- Dec 2009
- Posts
- 20
- Rep Power
- 0
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
-
How to identify packet type?
By priya deshpande in forum NetworkingReplies: 0Last Post: 10-11-2009, 06:40 AM -
Can't Stop packet from transmitting and unable to understand packet format
By khajalid in forum NetworkingReplies: 2Last Post: 12-22-2008, 03:05 AM -
Send Datagram packet to root server
By jammin in forum NetworkingReplies: 1Last Post: 11-15-2008, 12:23 AM -
fake ARP broadcast packet
By junkredish in forum NetworkingReplies: 0Last Post: 09-06-2008, 06:01 PM -
Bible-Discovery 2.1
By JavaBean in forum Java SoftwareReplies: 0Last Post: 10-25-2007, 04:19 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks