You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mina.apache.org by Lorenz Breu <br...@hot-shot.com> on 2008/11/06 14:57:54 UTC

UDP request/response, second attempt

Hi again

OK, these questions may seem dumb to you, so sorry for the inconvenience.
Anyway, has anybody ever implemented a request/response mechanism using
the Datagram classes in MINA (e.g. NIODatagramConnector)? My question is
if it was intended to be used in this way, i.e. if is possible for an
Acceptor's handler to do a session.write(reply) after receiving a
request and a Connector's handler to do a session.read(reply) after
sending the request. In java.io a socket can be read from after a send
event, but what I have to do now is prepare a connector (i.e. find a
free port), then start an acceptor on that port. When that is ready I
can send the request. The acceptor on the other side receives the
message and sends the reply back out through it's own connector to the
port the request came from. The original sender then receives the reply
on it's acceptor and disposes the acceptor once the message is received.
So for each request/reply the requester has to set up and dispose a new
acceptor, which may lead to unnecessary overhead(??). I was considering
adding a java.io "reply socket" to my AprDatagramSession, but that would
be a hack and wouldn't quite fit in with the rest of the framework.

So, to summarize, should it be possible to reply to a request within a
DatagramSession? Has it been done with the NIO stuff? If so, I would
continue looking for a solution in the APR transport classes.

Regards,
Lorenz

Re: UDP request/response, second attempt

Posted by Mark Webb <el...@gmail.com>.
Sure, it can be done.  the problem is that the packets could be
received on either end out of order, or not at all.  As long as you
are willing to accept these risks, you will be fine.



On Thu, Nov 6, 2008 at 8:57 AM, Lorenz Breu <br...@hot-shot.com> wrote:
> Hi again
>
> OK, these questions may seem dumb to you, so sorry for the inconvenience.
> Anyway, has anybody ever implemented a request/response mechanism using
> the Datagram classes in MINA (e.g. NIODatagramConnector)? My question is
> if it was intended to be used in this way, i.e. if is possible for an
> Acceptor's handler to do a session.write(reply) after receiving a
> request and a Connector's handler to do a session.read(reply) after
> sending the request. In java.io a socket can be read from after a send
> event, but what I have to do now is prepare a connector (i.e. find a
> free port), then start an acceptor on that port. When that is ready I
> can send the request. The acceptor on the other side receives the
> message and sends the reply back out through it's own connector to the
> port the request came from. The original sender then receives the reply
> on it's acceptor and disposes the acceptor once the message is received.
> So for each request/reply the requester has to set up and dispose a new
> acceptor, which may lead to unnecessary overhead(??). I was considering
> adding a java.io "reply socket" to my AprDatagramSession, but that would
> be a hack and wouldn't quite fit in with the rest of the framework.
>
> So, to summarize, should it be possible to reply to a request within a
> DatagramSession? Has it been done with the NIO stuff? If so, I would
> continue looking for a solution in the APR transport classes.
>
> Regards,
> Lorenz
>