the best way to talk to multiple UDP/TCP servers?

Wang Weijun weijun.wang at oracle.com
Thu Apr 24 08:58:24 UTC 2014


I'm playing with them now. UDP seems simpler, but TCP has more stages and seems I should carefully change the SelectionKey after each stage. Otherwise I see the select() method returning 0 immediately.

--Max

On Apr 24, 2014, at 16:19, Alan Bateman <Alan.Bateman at oracle.com> wrote:

> On 18/04/2014 16:21, Wang Weijun wrote:
>> I'm writing a client which talks to 3 servers, and would like to write a method that
>> 
>>   sends request to server 1 at time 0:01
>>   sends request to server 2 at time 0:02
>>   sends request to server 3 at time 0:03
>>   sends request to server 1 at time 0:11
>>   sends request to server 2 at time 0:12
>>   sends request to server 3 at time 0:13
>>   waits until 0:20
>> 
>> During this whole period, whenever a response from a server is received, the method returns and no more request is sent. The protocol can be UDP or TCP. What is the best way I can do this with NIO?
>> 
> You should be able to do this with non-blocking I/O and Selector, have you looked into that?
> 
> -Alan.



More information about the nio-dev mailing list