Hi,

That's because you're ignoring the exception and then continuing on with more sends on the same socket. If your receive times out you need to decide what to do with the connection - the server hasn't responded yet, but you don't know why. It might still respond later if the processing is taking longer than your timeout (which is what you're seeing here), or you might have some sort of firewall/NAT timeout that will cause all future requests to go into the void. Generally the safest approach is to send subsequent requests after a timeout on a new connection, but if you don't do this you need a way to match your requests and responses and ignore the responses that are for timed out requests.

Regards,
Brad.

tiandike wrote:
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.









Reply via email to