public String getPath() {
return "register";
}
});
BioUdpServer server = new BioUdpServer();
final RequestFilter<CoapMessage, CoapMessage> rq = new RequestFilter<>();
server.setFilters(new ProtocolCodecFilter<CoapMessage, ByteBuffer, Void, Void>(
new CoapEncoder(), new CoapDecoder()), rq);
// idle in 10 minute
server.getSessionConfig().setIdleTimeInMillis(IdleStatus.READ_IDLE, 60 * 10_000);
server.setIoHandler(new AbstractIoHandler() {
long start = System.currentTimeMillis();
int count = 0;
@Override
public void messageReceived(IoSession session, Object message) {
System.err.println("rcv : " + message);
CoapMessage resp = reg.respond((CoapMessage) message, session);
System.err.println("resp : " + resp);
session.write(resp);
count++;
if (count >= 100_000) {
System.err.println("time for 100k msg : " + (System.currentTimeMillis() - start));
count = 0;
start = System.currentTimeMillis();
}
}
@Override
public void messageSent(IoSession session, Object message) {
System.err.println("sent : " + message);
}
@Override
public void sessionIdle(IoSession session, IdleStatus status) {
System.err.println("idle closing");
session.close(false);
}
});
try {
server.bind(5683);
new Thread() {
@Override
public void run() {
for (;;) {
for (IoSession s : registration.values()) {