Question

I've created a mock XMPP server that processes PLAIN encryption stanzas. I'm able to use Pidgin and go through the entire session creation, to the point where Pidgin thinks the user is on an actually XMPP server and is sending regular pings.

However, it seems like not all messages are processed correctly and when I do get a successful login, it was just luck. I'm talking, maybe 1/10th of the time I actually get connected. The other times it seems like Pidgin missed a message or I dumped messages to fast on the transport.

If I enable Pidgin's XMPP Console plugin, the first connection is ALWAYS successful, but a second user fails to make it through, typically dying when Pidgin requests Service Discovery.

My Mina code is something like this:

    try
    {
        int PORT = 20600;

        IoAcceptor acceptor = null;
        acceptor = new NioSocketAcceptor();

        acceptor.getFilterChain().addFirst("codec", new ProtocolCodecFilter( new ProtocolCodecFactoryImpl()));
        acceptor.getFilterChain().addLast("executor", new ExecutorFilter(IoEventType.MESSAGE_RECEIVED));
        acceptor.setHandler( new SimpleServerHandler());    
        acceptor.getSessionConfig().setIdleTime(IdleStatus.BOTH_IDLE, 10);
        acceptor.bind( new InetSocketAddress(PORT));

    }
    catch (Exception ex)
    {
        System.out.println(ex.getMessage());
    }

and the SimpleServerHandler is responsible for message/stanza processing and session creation. The messageReceived function looks like:

@Override
public void messageReceived(IoSession session, Object msg) throws Exception
 {
    String str = msg.toString();
    System.out.println("MESSAGE: " + str);

    process(session, str);

}

and finally, process is in charge of parsing the message out, and writing the response. I do use sychonized on my write:

public void sessionWrite(IoSession session, String buf)
{
    synchronized(session)
    {
        WriteFuture future = session.write(buf);
    }
}

I have omitted my processing code for brevity, but it simply looks for certain pieces of data, crafts a response and calls sessionWrite(...)

My question is, will this pattern work? And if not, should I consider shoving received messages in a Queue and simply processing the Queue from say a Timer?

Was it helpful?

Solution

It turns out, Pidgin would send two IQ stanzas, but I wasn't handling them correctly. My decoder now determines the end of a stanza and only writes a stanza to the buffer I read from.

Works like a dream now!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top