admin 管理员组

文章数量: 1086019

I'm learning to use reactor-netty to create a TCP server with UI, and I have to do something like send a message to client then send other after 10s when I push a button.Here is my code

val fx = Flux<ReqContext>.create { sink ->
record10sButton.addActionListener(ActionListener { event: ActionEvent? ->
                sink.next(StartMessage)
                sleep(10000)
                sink.next(StopMessage)
                EventQueue.invokeLater{
                    JOptionPane.showMessageDialog(
                        this, "complete",
                        "record 10s",
                        JOptionPane.INFORMATION_MESSAGE
                    )
                }
            })
}

The above code is the listener of the button, I copy and modify it from reactor document

val tcpServer =
            TcpServer.create()
                .host("localhost")
                .port(50000)
                .handle { inbound: NettyInbound?, outbound: NettyOutbound? ->
                        inbound!!.receiveObject().then().
                        and(outbound!!.sendObject(fx).then())
                }
                .wiretap(true)

And here is the code of server

The behavior of this button confused me, the interval of two message seems related on the number of connection, when 3 clients connected, client receive second message after 30s. I want to know how to fix that

本文标签: kotlinHow to use flux to send 2 message at fixed intervalsStack Overflow