If i  use receive with timeout:
   Object[] res=new Object[num];
        for(int i=0;i<num;i++){
        System.out.println("send: " + i);                               
        try {
        connection.send(i);
        res[i]=connection.receive(500);
        } catch (Exception e) {
                                        
        }

        System.out.println("echo: " + res[i]);
                                
                        }  

I find it will lead a question:
the result below is :
send: 0
echo: null
send: 1
echo: echo0
send: 2
echo: null
send: 3
echo: echo1
send: 4
echo: echo2
send: 5
echo: null
send: 6
echo: echo3
send: 7      

it leads the request and response not match.




Brad Harvey-2 wrote:
> 
> Hi Tiandike,
> 
> Another way of doing it is at 
> https://issues.apache.org/jira/browse/DIRMINA-375.  I can't promise that 
> it's better :) 
> 
> Here's what your Client1 would become (hopefully there aren't too many 
> mistakes - I'm typing this directly into the email):
> 
> InetSocketAddress socketAddress = new InetSocketAddress("localhost",
> 8080);
> IoServiceConfig config = new SocketConnectorConfig();
> DefaultIoFilterChainBuilder filterChainBuilder = new 
> DefaultIoFilterChainBuilder();
> filterChainBuilder.addLast("codec",  new ProtocolCodecFilter(
>                                     new
> SumUpProtocolCodecFactory(false)));
> 
> config.setFilterChainBuilder(filterChainBuilder);
> 
> // The ConnectionFactory creates new synchronous connections with the 
> given address & config.
> ConnectionFactory cf = new ConnectionFactoryImpl(socketAddress, config);
> // createConnection does the actual connect (blocking only).
> NonBlockingConnection connection = cf.createConnection();
> 
> try {
> 
>             for (int i = 0; i < values.length; i++) {
>                  AddMessage m = new AddMessage();
>                  m.setSequence(i);
>                  m.setValue(values[i]);
>                  connection.send(m);
>                  Object res=connection.receive();           
>                  if(res instanceof ResultMessage){
>                      System.out.println("return "+(ResultMessage)res);
>                  }
> 
>             }
> finally {
>    connection.close();
> }
> 
> Regards,
> Brad.
> 
> tiandike wrote:
>> N http://www.nabble.com/file/p12286978/sumup.rar sumup.rar ow i use
>> callback
>> and wait notify  to implement the syn call.
>> I want to know if there are any better solutions.
>>
>> I modify the sumup example to implent syn call.
>>
>> the client has three java files :client1.java  ClientSessionHandler1.java 
>> ClientSupport.java
>>
>> my CallBack interface is 
>> interface CallBack  {
>>              
>>              void setMessage(Object message);
>>              
>>      }
>>
>> ClientSupport implements CallBack and has  connect  , send and quit
>> functions
>>
>> the send function return the result from server.
>>
>> the client1 can use ClientSupport's send function to syn request and get
>> response from server.
>>
>>
>>
>>
>>
>>
>>
>>
>>   
> 
> 

-- 
View this message in context: 
http://www.nabble.com/How-to-implement-the-synchronized-function-call--tf4310316s16868.html#a13502527
Sent from the Apache MINA Support Forum mailing list archive at Nabble.com.

Reply via email to