You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mina.apache.org by Santos xyz <sa...@hotmail.com> on 2007/02/08 17:36:46 UTC

Using mina for client purpose

I wrote a program to use mina-1.1 as client based on the example sumupr. I 
have copied the relevant section below. I see following issues:

1. Even on server side I see client connected, isConnected returns false.
2.  session.getCloseFuture().join() throws exception.


Failed to connect.
org.apache.mina.common.RuntimeIOException: Failed to get the session.
	at 
org.apache.mina.common.support.DefaultConnectFuture.getSession(DefaultConnectFuture.java:62)
	at com.dogpile.server.mina.FlowConsumer.Client.main(Client.java:65)
Caused by: org.apache.mina.filter.codec.ProtocolEncoderException: Unexpected 
message type: class com.dogpile.server.mina.Message.DataRequestMessage
	at 
org.apache.mina.filter.codec.demux.DemuxingProtocolCodecFactory$ProtocolEncoderImpl.encode(DemuxingProtocolCodecFactory.java:203)

Thank you.
sj

---Code------

SocketConnector connector = new SocketConnector();

	        // Change the worker timeout to 1 second to make the I/O thread 
quit soon
	        // when there's no connection to manage.
	        connector.setWorkerTimeout( 30 );

	        // Configure the service.
	        SocketConnectorConfig cfg = new SocketConnectorConfig();
	        cfg.setConnectTimeout( CONNECT_TIMEOUT );
	        if( USE_CUSTOM_CODEC )
	        {
	            cfg.getFilterChain().addLast(
	                    "codec",
	                    new ProtocolCodecFilter( new 
RouterProtocolCodecFactory( false ) ) );
	        }
	        else
	        {
	            cfg.getFilterChain().addLast(
	                    "codec",
	                    new ProtocolCodecFilter( new 
ObjectSerializationCodecFactory() ) );
	        }
	        cfg.getFilterChain().addLast( "logger", new LoggingFilter() );

	        IoSession session=null;

	            try
	            {


	                ConnectFuture future = connector.connect(
	                        new InetSocketAddress( HOSTNAME, PORT ),
	                        new ClientSessionHandler(MessageCreator.getMsg()), 
cfg );
	                System.out.println("is Client 
connected="+future.isConnected());

	                future.join();
	                System.out.println("is Client connected After 
Join="+future.isConnected());
	                session = future.getSession();

	            }
	            catch( RuntimeIOException e )
	            {
	                System.err.println( "Failed to connect." );
	                e.printStackTrace();
	                Thread.sleep( 5000 );
	            }


	        // wait until the summation is done
	        session.getCloseFuture().join();
	    }

_________________________________________________________________
>From predictions to trailers, check out the MSN Entertainment Guide to the 
Academy AwardsŽ 
http://movies.msn.com/movies/oscars2007/?icid=ncoscartagline1


Re: Using mina for client purpose

Posted by peter royal <pr...@apache.org>.
On Feb 8, 2007, at 8:36 AM, Santos xyz wrote:
> Failed to connect.
> org.apache.mina.common.RuntimeIOException: Failed to get the session.
> 	at org.apache.mina.common.support.DefaultConnectFuture.getSession 
> (DefaultConnectFuture.java:62)
> 	at com.dogpile.server.mina.FlowConsumer.Client.main(Client.java:65)
> Caused by: org.apache.mina.filter.codec.ProtocolEncoderException:  
> Unexpected message type: class  
> com.dogpile.server.mina.Message.DataRequestMessage
> 	at org.apache.mina.filter.codec.demux.DemuxingProtocolCodecFactory 
> $ProtocolEncoderImpl.encode(DemuxingProtocolCodecFactory.java:203)



> 	                    new ProtocolCodecFilter( new  
> RouterProtocolCodecFactory( false ) ) );

It sounds like your RouterProtocolCodecFactory doesn't properly know  
how to encode your DataRequestMessage class?

-pete


-- 
proyal@apache.org - http://fotap.org/~osi