i mean: my program dont have connection all the time, but periodically connects to jabber server; on other side there are jabber client (Exodus). Main task of my software - create bidirectional message session (or chat) between web-client and instant messenger.
i created simple prototype, but now i can only send messages from web-client.
I think the problem is that you can only open chat sessions with a given or new id. Is there also a possibility to retrieve non-chat messages or to accept chats with an unknown id ?
You can register a PacketCollector or PacketListener to listen for any messages (use the PacketTypeFilter). Eventually, we’'ll add a special filter that can listen for new conversations.
If you read the Javadocs for pollMessage() you’'ll see that it always returns immediately, even if no results are present. You probably want to try the methods:
Chat.nextMessage() or
Chat.nextMessage(long timeout)
Also, what you’‘re trying won’‘t quite work unless your server is setup for offline delivery. Even then, you could run into a problem since the server could send the message to the second connection before the packet collector is registered. It looks like this is a JSP page? In that case, I’‘d recommend making the connection object persistent across page views. You could do this by adding it to the user’‘s session, having a seperate cache for connection objects, or by making the connection a static variable (although that might not work well). Once connections live across multiple page views, I think you’'ll find things work better.
But today ive found some problem (even in console application) - smack (xml parser) reports exception when im trying to send message to application. (there are font definition in message and looks like parser dont understand it)
That’‘s an invalid message – you’‘re not allowed to use any XML inside the body tag. So, you’'ll either need to encode it (convert < to <, etc) or use the xhtml message format (see jabber.org).