Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [cf-dev] Multiple response to one request

Sorry for posting 2 times in a row, but i have investigated the problem.
With wireshark, I clearly see 2 frames sent from the server to the client: an empty ACK + an ACK (or CON depending if i set it).
The latest is handle by the coap handler, in the asynchronous method onLoad.

I made also some other tests with for example sending 2 responses with a content simply like that:

@Override
public void handlePUT(CoapExchange exchange) {

	exchange.response(VALID);
        Thread.currentThread().sleep(5000); // removed the try catch clause
	exchange.respond(CHANGED); 
}

Again with wireshark i see those 2 frames.
But here, it's different: the client handle just the first response and ignore the second.

Finally, i tried also with a synchronous client and testing with something like that: 
Request request = new Request(Code.PUT);
request.setPayload("a");
request.setURI("coap://localhost:5683/myCoolURI");
request.send();
Message firstResp = request.waitForResponse();
System.out.println(firstRep);
Message secondResp = request.waitForResponse();
System.out.println(secondResp);

It didn't reach the second print statement.

I guess, the problem is in the client side because the server correctly send the coap frame to the client.

Best regards,
Laurent.

/** 
* Laurent Lemke 
* Doctorant CIFRE - Orange Labs 
* Université de Grenoble: équipe ERODS (LIG) & équipe Synchrone (VERIMAG) 
*/ 

----- Mail original -----
De: "Laurent Lemke" <laurent.lemke@xxxxxxx>
À: "Californium (Cf) developer discussions" <cf-dev@xxxxxxxxxxx>
Envoyé: Samedi 13 Décembre 2014 18:21:43
Objet: Re: [cf-dev] Multiple response to one request

Hi Matthias,

Thanks for your answer.
I understand the meaning of your answer, using a piggybacked response (for the first response which correspond to the accept() method in your code <=> an ACK response).
But I'm stuck with the client side where I can read only the second response (with the CHANGED ResponseCode in your example).
It's a very basic sample code inside my onLoad method which consists to print some information about the response received (type, token, etc..).

Any idea to handle the 2 responses ?

Thanks,

Best regards,
Laurent.


/** 
* Laurent Lemke 
* Doctorant CIFRE - Orange Labs 
* Université de Grenoble: équipe ERODS (LIG) & équipe Synchrone (VERIMAG) 
*/ 

----- Mail original -----
De: "Kovatsch Matthias" <kovatsch@xxxxxxxxxxx>
À: "Californium (Cf) developer discussions" <cf-dev@xxxxxxxxxxx>
Envoyé: Samedi 13 Décembre 2014 00:37:36
Objet: Re: [cf-dev] Multiple response to one request

Hi Laurent

The correct way to do this is using separate responses:

@Override
public void handlePUT(CoapExchange exchange) {
	// make it a separate response
	exchange.accept();

	// your long-lasting task
        
	// finish with the response
	exchange.respond(CHANGED); // reply with response code only (shortcut)
}

On the client side you can either use an asynchronous request with a CoapHandler or you run a synchronous request in a dedicated thread.

Ciao
Matthias

> -----Original Message-----
> From: cf-dev-bounces@xxxxxxxxxxx [mailto:cf-dev-bounces@xxxxxxxxxxx] On
> Behalf Of Laurent Lemke
> Sent: Freitag, 12. Dezember 2014 21:12
> To: cf-dev@xxxxxxxxxxx
> Subject: [cf-dev] Multiple response to one request
> 
> Hello everybody,
> 
> I'm currently using californium and I'm trying to have this kind of scenario, a
> client/server communication :
> - Client send a request which correspond to an action that take some time
> (so a POST or PUT, in my case it's a PUT..)
> - Server send a first response, indicating to the client that he will do the best
> for doing this action (kind of ACCEPTED code response) ... the action is
> perform and taking a lot of time ...
> - Server send a second response indicating that the action has been
> successfully perform.
> 
> But well, when i'm trying to do program it with Californium i got stuck.
> Basically, it seems that a client cannot get multiple response for one request,
> right ?
> I mean, i exclude the "observe" property which is not suitable in my case.
> Because as far as i know, observe rely to the GET verb.. and i'm using a PUT
> verb here.
> 
> A possible solution, correct me if i am wrong (or if it's not relevant),  would be
> to have an asynchronous handler that is associated to a token ?
> Because currently, the asynchronous handler handle just one request.
> 
> Best regards,
> 
> Laurent Lemke.
> 
> 
> /**
> * Laurent Lemke
> * Doctorant CIFRE - Orange Labs
> * Université de Grenoble: équipe ERODS (LIG) & équipe Synchrone
> (VERIMAG) */
> 
> _______________________________________________
> cf-dev mailing list
> cf-dev@xxxxxxxxxxx
> To change your delivery options, retrieve your password, or unsubscribe
> from this list, visit https://dev.eclipse.org/mailman/listinfo/cf-dev
_______________________________________________
cf-dev mailing list
cf-dev@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/cf-dev
_______________________________________________
cf-dev mailing list
cf-dev@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/cf-dev


Back to the top