## [A3|Milestone 4] Sending replies

Moderator: Praktikum: Internet

LukasRos
Mausschubser
Beiträge: 63
Registriert: 26. Okt 2004 13:54

### [A3|Milestone 4] Sending replies

I'm working on Milestone 4 and got stuck when trying to send a reply to the sender to tell him to change redundancy settings.
My code is this:

Code: Alles auswählen

TypedMap rmap = new TypedMap();
rmap.putInt("sender_id", 0);
rmap.putInt("seq", 0);
Message reply = new Message(rmap);


Yes, I know that I place the information twice - once in the "general" map and as additional headers, that was done intentionally.
But what I get is a NullPointerException from BinCollectHandler, pointing to the serializeString. What does this handler expect here, how can I format my reply message so that it is accepted?

erwin.ait
Erstie
Beiträge: 20
Registriert: 23. Jul 2007 16:34

### Re: [A3|Milestone 4] Sending replies

Looks like you forgot msg.setType(mimeType); Please see samples/handlers/ex4 how to send reply messages.

sander
Nichts ist wie es scheint
Beiträge: 23
Registriert: 2. Dez 2003 16:42

### Re: [A3|Milestone 4] Sending replies

Hi!

For MS4 our handler uses reply messages to control the amount of redundancy. After sending a certain number of messages our handler adds a XOR message. If the handler on the receiver side notices packet loss it informs the handler on the sender side to increase the amount of redundancy by sending a reply message:

Code: Alles auswählen

        TypedMap ctrl = new TypedMap();
ctrl.putString("request", "control");
ctrl.putString("mode", "set");
Message ctrlMsg = new Message();
ctrlMsg.setType(mimeType);

The problem is, that if our TestSender-Application send it's messages to fast, our handler does not receive these control messages in time:

Code: Alles auswählen

 for (int i=1; i<=NUM_MESSAGES; i++)
{
TypedMap map = new TypedMap();
map.putInt("seq", i);
Message msg = new Message(map);
publisher.send(msg);

numMsgSent++;
}

If we increase the time between 2 messages from Thread.sleep(1) to Thread.sleep(100) everything seems to work.

Is there a way to make the handler wait for a control message before sending further messages?

erwin.ait
Erstie
Beiträge: 20
Registriert: 23. Jul 2007 16:34

### Re: [A3|Milestone 4] Sending replies

Thread.sleep(1) means basically that you are trying to send 1000 messages/sec. Depending on the speed of your computer, this might already be close to the limit. Maybe use something like Thread.sleep(10).
sander hat geschrieben: The problem is, that if our TestSender-Application send it's messages to fast, our handler does not receive these control messages in time:
It should be no problem if your handler receives the control message a bit delayed. In addition, sending a control message for each received data packet would cause too much additional traffic.
sander hat geschrieben: Is there a way to make the handler wait for a control message before sending further messages?
The overall design of the handler should be asynchronous and not synchronous. Don't introduce such tight couplings between data and control messages.