java实现ssdp协议_SSDP协议最简单的Reactor / Netty实现是什么?

java实现ssdp协议_SSDP协议最简单的Reactor / Netty实现是什么?对于那些感兴趣的人,这是一个片段.我能够通过FluxLauncher而不是reactor-nettyUDP类来实现.privatestaticfinalStringSSDP_IP="239.255.255.250";privatestaticfinalintSSDP_PORT=1900;privatestaticfinalintTIMEOUT=500...

对于那些感兴趣的人,这是一个片段 . 我能够通过Flux Launcher 而不是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 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()))

架构君码字不易,如需转载,请注明出处:https://javajgs.com/archives/166076
0

发表评论