// CLIENT CODE SNIPPET THAT SHOWS PROBLEM
public class bgMinaClient extends IoHandlerAdapter
{
public static final int CONNECT_TIMEOUT = 3000;
private String host;
private int port;
private String tokenizer;
private SocketConnector connector;
private IoSession session;
private bgClientListener clientListener;
private ConnectFuture connectFuture;
public bgMinaClient(String host, int port, String tokenizer,
bgClientListener clientListener) {
this.host = host;
this.port = port;
this.tokenizer = tokenizer;
this.clientListener = clientListener;
connector = new SocketConnector();
connector.getFilterChain().addLast("codec", new
ProtocolCodecFilter(new bgCodecFactory(true)));
}
public void connect() {
connectFuture = connector.connect(new
InetSocketAddress(host,port), this);
connectFuture.join(CONNECT_TIMEOUT);
try
{
session = connectFuture.getSession();
}
catch (RuntimeIOException e)
{
clientListener.onException( e );
}
}
public void disconnect() {
if (session != null)
{
session.close().join(CONNECT_TIMEOUT);
session = null;
}
}
public void sessionOpened(IoSession session) throws Exception {
// this method was being called and the session seemed to be established
// setting my memeber session variable was added here to fix the 'bug'
this.session = session;
clientListener.doConnect( session );
}
public void sessionClosed(IoSession session) throws Exception {
clientListener.doDisconnect();
}
public void sendRequest( bgClientRequest clientRequest ) {
/// at this point session would always be NULL until I set it in
sessionOpened!
if (session == null) {
clientListener.onException(new Throwable("not connected"));
}
else
{
session.write(clientRequest);
}
}
}
//SERVER CODE SNIPPET JUST FOR FUN
public class bgMinaServer {
// defines how messages are split into parts
final String tokenizer;
// commPort used for communications
final int commPort;
// the acceptor object
IoAcceptor acceptor = null;
// the socket acceptor configuration
SocketAcceptorConfig cfg;
// the server handler object
bgMinaServerHandler handler;
bgServerListener serverListener;
public bgMinaServer ( int commPort, String tokenizer,
bgServerListener serverListener ) {
this.serverListener = serverListener;
this.commPort = commPort;
this.tokenizer = tokenizer;
ByteBuffer.setUseDirectBuffers(false);
ByteBuffer.setAllocator(new SimpleByteBufferAllocator());
acceptor = new SocketAcceptor();
cfg = new SocketAcceptorConfig();
cfg.getSessionConfig().setReuseAddress( true );
cfg.getFilterChain().addLast( "logger", new LoggingFilter() );
cfg.getFilterChain().addLast( "protocol", new
ProtocolCodecFilter(new bgCodecFactory(false)));
}
public void start() {
try {
handler = new bgMinaServerHandler();
handler.serverListener = this.serverListener;
handler.tokenizer = this.tokenizer;
acceptor.bind( new InetSocketAddress( commPort ), handler, cfg);
System.out.println("Game server started.");
} catch (IOException e) {
e.printStackTrace();
}
}
}
On 7/25/07, Kevin Smeltzer <[EMAIL PROTECTED]> wrote:
Can I create a bug report for this software? I'm only a user of Mina
not a developer.
The reason I ask is that I went to the page and I don't see an add
button anywhere :-P
On 7/25/07, Maarten Bosteels <[EMAIL PROTECTED]> wrote:
> Kevin,
>
> When you suspect you have discovered a bug or a missing feature, it's best
> to create a JIRA issue for this.
>
> http://issues.apache.org/jira/browse/DIRMINA
>
> Thanks,
>
> Maarten
>
>
> On 7/25/07, Kevin Smeltzer <[EMAIL PROTECTED]> wrote:
> >
> > Sure what is the best way to send? As an attachment or in the body of
> > the e-mail?
> >
> > On 7/25/07, Trustin Lee <[EMAIL PROTECTED]> wrote:
> > > On 7/25/07, Kevin Smeltzer <[EMAIL PROTECTED]> wrote:
> > > > Yes I did that. The connection IS made.
> > > >
> > > > It appears that the IoSession reference returned by this code:
> > > >
> > > > session = connectFuture.getSession();
> > > >
> > > > Is different than the IoSession reference passed to this method:
> > > >
> > > > public void sessionOpened(IoSession session) throws Exception {}
> > > >
> > > > So... by setting my IoSession member variable to reference the
> > > > IoSession passed to sessionOpened, it works.
> > > >
> > > > But shouldn't the IoSession returned by connectFuture.getSession();
> > > > and public void sessionOpened(IoSession session) throws Exception {}
> > > > be the same?
> > >
> > > They should be the same. It's weird. I suspect a bug. Could you
> > > provide reproduceable client and server?
> > >
> > > Trustin
> > > --
> > > what we call human nature is actually human habit
> > > --
> > > http://gleamynode.net/
> > > --
> > > PGP Key ID: 0x0255ECA6
> > >
> >
>