1

I want to create an android application that can capture MDNS advertisement send by a device connected to my network. I want to get the response as

NOTIFY * HTTP/1.1
HOST: 239.255.255.250:1900
CACHE-CONTROL: max-age = seconds until advertisement expires
LOCATION: URL of the web page to advertise
NT: urn:physical-web-org:device:Basic:1
NTS: ssdp:alive
SERVER: OS/version UPnP/1.0 product/version
USN: advertisement UUID 

Can anyone help me to convert response like above?

Sonia John Kavery
  • 2,099
  • 2
  • 20
  • 36

1 Answers1

3

try this code

buffer = new byte[1024]; 
packet = new DatagramPacket(buffer, buffer.length);
socket.receive(packet);
buffer = packet.getData();
String packetAsString=new String(buffer, 0, packet.getLength());
Log.d("DatagramPacket","Received: "+packetAsString);

see this link Datagrampacket to String

Community
  • 1
  • 1
kamlesh gorasiya
  • 273
  • 2
  • 10