在C代码中有这个recvfrom函数,你可以找到发件人的IP地址。
recvfrom(s, buffer, sizeof buffer, 0, (struct sockaddr *)&fromAddr, &fromAddrLen);
但在Android中,数据是
byte[] buf = new byte[17];
/* Prepare a UDP-Packet that can
* contain the data we want to receive */
DatagramPacket packet = new DatagramPacket(buf, buf.length);
/* Receive the UDP-Packet */
socket.receive(packet);
那么,在Android中如何提取发件人的IP地址?