okleine / nCoAP

Java implementation of the CoAP protocol using netty
BSD 3-Clause "New" or "Revised" License
179 stars 57 forks source link

Separate response does not work properly #10

Closed stefanhueske closed 12 years ago

stefanhueske commented 12 years ago

CON-Response will not be forwarded to ResponseCallbackHandler

public class IncomingMessageReliabilityHandler extends SimpleChannelHandler {
    //[...]
    public void messageReceived(ChannelHandlerContext ctx, MessageEvent me) throws Exception{
        //incoming separate response is CON and COAPResponse
        if(!(me.getMessage() instanceof CoapMessage)){
            ctx.sendUpstream(me);
            return;
        }

        CoapMessage coapMessage = (CoapMessage) me.getMessage();

        if(coapMessage.getMessageType() != MsgType.CON){
            ctx.sendUpstream(me);
            return;
        }

        if(coapMessage instanceof CoapRequest){
            //[...]
        } else{
            EmptyACKSender emptyACKSender = new EmptyACKSender((InetSocketAddress) me.getRemoteAddress(),
                                                                    coapMessage.getMessageID());
            //Schedule to send an empty ACK asap
            executorService.schedule(emptyACKSender, 0, TimeUnit.MILLISECONDS);
        }
        //==> coapMessage is lost and callback will never called.
    }
    //[...]
}