SSDP 协议最简单的 Reactor / Netty 实现是什么?
What is the most simple Reactor / Netty implementation for SSDP protocol?
我用 UdpClient、UdpServer、Spring Integration Ip 模块尝试了很多东西,将 DatagramSocket 接收方法包装到 return Flux,但我根本无法从标准 SSDP 239.255 收到任何响应。 255.250:1900.
同时向 SSDP 发送数据包的奖励积分。
对于那些感兴趣的人,这里有一个片段。我能够通过 Flux emitter 而不是 reactor-netty UDP 类.
private static final String SSDP_IP = "239.255.255.250";
private static final int SSDP_PORT = 1900;
private static final int TIMEOUT = 5000;
String request = new String("example");
byte[] receiveData = new byte[1024];
DatagramPacket sendPacket = new DatagramPacket(request.getBytes(),
request.getBytes().length, InetAddress.getByName(SSDP_IP), SSDP_PORT);
DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length,
InetAddress.getLocalHost(), SSDP_PORT);
Flux<String> response = Flux.create(emitter -> {
try (DatagramSocket socket = new DatagramSocket()) {
socket.setSoTimeout(TIMEOUT);
socket.send(sendPacket);
while (true) {
socket.receive(receivePacket);
emitter.next(receivePacket.getData());
}
} catch (SocketTimeoutException e) {
emitter.complete();
} catch (IOException e) {
emitter.error(e);
}
})
.map(mapper -> new String(receivePacket.getData(), 0, receivePacket.getLength()))
我用 UdpClient、UdpServer、Spring Integration Ip 模块尝试了很多东西,将 DatagramSocket 接收方法包装到 return Flux,但我根本无法从标准 SSDP 239.255 收到任何响应。 255.250:1900.
同时向 SSDP 发送数据包的奖励积分。
对于那些感兴趣的人,这里有一个片段。我能够通过 Flux emitter 而不是 reactor-netty UDP 类.
private static final String SSDP_IP = "239.255.255.250";
private static final int SSDP_PORT = 1900;
private static final int TIMEOUT = 5000;
String request = new String("example");
byte[] receiveData = new byte[1024];
DatagramPacket sendPacket = new DatagramPacket(request.getBytes(),
request.getBytes().length, InetAddress.getByName(SSDP_IP), SSDP_PORT);
DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length,
InetAddress.getLocalHost(), SSDP_PORT);
Flux<String> response = Flux.create(emitter -> {
try (DatagramSocket socket = new DatagramSocket()) {
socket.setSoTimeout(TIMEOUT);
socket.send(sendPacket);
while (true) {
socket.receive(receivePacket);
emitter.next(receivePacket.getData());
}
} catch (SocketTimeoutException e) {
emitter.complete();
} catch (IOException e) {
emitter.error(e);
}
})
.map(mapper -> new String(receivePacket.getData(), 0, receivePacket.getLength()))