Your approach is perfectly fine. There is one thing that you need to change at the client side. You need to implement the Observer or Listener pattern. Each of your message need to be uniquely identified. When a message is sent, the client thread shall become observer and wait till a message arrives. Ones the message arrives the listener should pick up the packet, identify the listener and call a callback method.
You can choose any any data structure/strategy for this. Summarizing 1. Have a unique identifier for your messages 2. Add sender into Observer list with unique id 3. Server should return the unique id back 4. Once the response is received, based on the unique id, call a callback method on Observer Alternatively, you can create an abstraction that Client thread doesn't use network directly. Build a network handler and let it do all this stuff. Client This kind of implementation is fairly common in Network Manager. Checkout AdventNet or SNMP4J code samples. - ashish On Wed, Nov 5, 2008 at 3:22 AM, Yong Yuan <[EMAIL PROTECTED]> wrote: > Hi, > > I'm building a UDP server that handles each incoming request in a separate > thread. The problem is, a UDP client may send out multiple requests > concurrently by using multiple threads. Each thread on the client will wait > for responses from the server. Since UDP is connectionless, a client thread > may receive a mismatching datagram. In this case, does MINA have any > built-in mechanism that helps a client thread to get the matching response? > If not, I guess we can build a queue that dispatches responses to > appropriate client threads. However, what if I need to run multiple clients > in different JVMs on the same client machine, and each client will make > requests to the same server? Is there any good way of handling such > scenario, or we should really use TCP in this case? > > Thanks, > -- thanks ashish Blog: http://www.ashishpaliwal.com/blog My Photo Galleries: http://www.pbase.com/ashishpaliwal
