1

i'm working on an Java client-server application.

The client send a message sequence (the messages can be different types, i,ve got header), and listens for the replies. I've got 2 thread, one for the transmission and one for the receipts. So i need to handle the replies, in case of errors or in case of the replies doesn't arrive, for example i can try to send the message another time.

My question is.. is there any java patterns that can helps me?

i would like to handle the send and the relative repliy like a single transaction, but note that i don't need to have a synchronous communication. I send all the message in the sequence in the TX thread and wait for the replies on the RX thread.

I've thought to the mediator Pattern, but i don't know if it is the right way.

Thanks

4

1 回答 1

0

如果问题纯粹是关于传输协议,我会看看 NAK。 http://en.wikipedia.org/wiki/NAK_(protocol_message)

我已经实现了一个名为 JCast 的协议,它通过多播发送文件。这些文件被分解成带有编号的小片段。接收客户端然后用它没有得到的任何丢失的片段(这些是 NAK 的)进行响应。然后服务器将只重新发送 NAK 的片段。

编辑:NAK 优于 ACK 的好处是服务器可以发送它需要的所有数据包,而无需等待 ACK。由于现在网络已经大大改善,大部分数据包都会到达。少数没有到达的人只会被怨恨。

于 2013-10-30T21:43:43.180 回答