正在查看: Chaupal v3.2 应用的 SSDPClient.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
正在查看: Chaupal v3.2 应用的 SSDPClient.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
package com.connectsdk.discovery.provider.ssdp;
import com.google.ads.interactivemedia.v3.internal.aen;
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.MulticastSocket;
import java.net.NetworkInterface;
import java.net.SocketAddress;
import java.net.SocketException;
public class SSDPClient {
public static final String ALIVE = "ssdp:alive";
public static final String BYEBYE = "ssdp:byebye";
public static final String MSEARCH = "M-SEARCH * HTTP/1.1";
public static final String MULTICAST_ADDRESS = "239.255.255.250";
static int MX = 5;
public static final String NEWLINE = "\r\n";
public static final String NOTIFY = "NOTIFY * HTTP/1.1";
public static final String OK = "HTTP/1.1 200 OK";
public static final int PORT = 1900;
public static final String UPDATE = "ssdp:update";
DatagramSocket datagramSocket;
InetAddress localInAddress;
SocketAddress multicastGroup;
MulticastSocket multicastSocket;
NetworkInterface networkInterface;
int timeout;
public SSDPClient(InetAddress inetAddress) throws IOException {
this(inetAddress, new MulticastSocket(PORT), new DatagramSocket((SocketAddress) null));
}
public static String getSSDPSearchMessage(String str) {
StringBuilder sb = new StringBuilder();
sb.append("M-SEARCH * HTTP/1.1\r\n");
sb.append("HOST: 239.255.255.250:1900\r\n");
sb.append("MAN: \"ssdp:discover\"\r\n");
sb.append("ST: ");
sb.append(str);
sb.append("\r\n");
sb.append("MX: ");
sb.append(MX);
sb.append("\r\n");
if (str.contains("udap")) {
sb.append("USER-AGENT: UDAP/2.0\r\n");
}
sb.append("\r\n");
return sb.toString();
}
public void close() {
MulticastSocket multicastSocket = this.multicastSocket;
if (multicastSocket != null) {
try {
multicastSocket.leaveGroup(this.multicastGroup, this.networkInterface);
} catch (IOException unused) {
}
this.multicastSocket.close();
}
DatagramSocket datagramSocket = this.datagramSocket;
if (datagramSocket != null) {
if (datagramSocket.isConnected()) {
this.datagramSocket.disconnect();
}
if (this.datagramSocket.isClosed()) {
return;
}
this.datagramSocket.close();
}
}
public boolean isConnected() {
DatagramSocket datagramSocket = this.datagramSocket;
return datagramSocket != null && this.multicastSocket != null && datagramSocket.isConnected() && this.multicastSocket.isConnected();
}
public DatagramPacket multicastReceive() throws IOException {
DatagramPacket datagramPacket = new DatagramPacket(new byte[aen.f10468r], aen.f10468r);
this.multicastSocket.receive(datagramPacket);
return datagramPacket;
}
public DatagramPacket responseReceive() throws IOException {
DatagramPacket datagramPacket = new DatagramPacket(new byte[aen.f10468r], aen.f10468r);
this.datagramSocket.receive(datagramPacket);
return datagramPacket;
}
public void send(String str) throws IOException {
this.datagramSocket.send(new DatagramPacket(str.getBytes(), str.length(), this.multicastGroup));
}
public void setTimeout(int i7) throws SocketException {
this.timeout = i7;
this.datagramSocket.setSoTimeout(i7);
}
public SSDPClient(InetAddress inetAddress, MulticastSocket multicastSocket, DatagramSocket datagramSocket) throws IOException {
this.timeout = 0;
this.localInAddress = inetAddress;
this.multicastSocket = multicastSocket;
this.datagramSocket = datagramSocket;
this.multicastGroup = new InetSocketAddress(MULTICAST_ADDRESS, PORT);
NetworkInterface byInetAddress = NetworkInterface.getByInetAddress(this.localInAddress);
this.networkInterface = byInetAddress;
this.multicastSocket.joinGroup(this.multicastGroup, byInetAddress);
this.datagramSocket.setReuseAddress(true);
this.datagramSocket.bind(new InetSocketAddress(this.localInAddress, 0));
}
}