Hi, to build and test the tutorial of this book: http://eclipserpc.org
I built a simple echo-chat-bot on my Google App account, to connect to it from the chat client tutorial of the book. My bot is now working by echoing whatever written to, from my GoogleTalk: [email protected]. I fail with connecting the chat client of the tutorial to it. I think my problem is that I don't know how express the connection in program. Bellow I provide the problem in detail, and there all the tutorial code I used both for the server bot and the client (from the book). Please give some ideas to help to solve the issue (connection time out). The tutorial main class: public class Application implements IApplication, MessageListener { public Object start(IApplicationContext context) throws Exception { XMPPConnection con = new XMPPConnection("eclipsercp.org"); try { con.connect(); con.login("reader", "secret", Long.toString(System.currentTimeMillis())); Chat chat = con.getChatManager().createChat("[email protected]", this); chat.sendMessage("Hi There!"); Thread.sleep(5000); } catch (XMPPException e) { e.printStackTrace(); } finally { con.disconnect(); } return IApplication.EXIT_OK; } //... Please tell me, if the right way is to change "eclipsercp.org" there for "talk.google.com" and the "[email protected]" with "[email protected]"? if so points: 1. I built the Google App using the Eclipse plugin of GApp and deployed successfully, so my internet connection and Eclipse setup is correct. 2. My Google Talk connects to the bot, so connecting is also possible without problem. 3. I have no login/password authentication on the bot, but the tutorial has, well I suppose I can leave them as-is, as chat-bot just ignore them. =============================================================== Complete source code I used to try Google App with XMPP: the server code (bot): **************************************************************************************************** package com.gaejexperiments.xmpptutorial; import java.io.IOException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.google.appengine.api.xmpp.*; import java.util.logging.Level; import java.util.logging.Logger; @SuppressWarnings("serial") //STEP 1 public class XMPPAgentServlet extends HttpServlet { public static final Logger _log = Logger.getLogger(XMPPAgentServlet.class.getName()); public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException { try { String strStatus = ""; XMPPService xmpp = XMPPServiceFactory.getXMPPService(); //STEP 2 Message msg = xmpp.parseMessage(req); JID fromJid = msg.getFromJid(); String body = msg.getBody(); _log.info("Received a message from " + fromJid + " and body = " + body); //STEP 3 String msgBody = "You sent me : " + body + "I am still learning Human created languages! Soon I'll have a better chat with you ;-)"; Message replyMessage = new MessageBuilder() .withRecipientJids(fromJid) .withBody(msgBody) .build(); //STEP 4 boolean messageSent = false; if (xmpp.getPresence(fromJid).isAvailable()) { SendResponse status = xmpp.sendMessage(replyMessage); messageSent = (status.getStatusMap().get(fromJid) == SendResponse.Status.SUCCESS); } //STEP 5 if (messageSent) { strStatus = "Message has been sent successfully"; } else { strStatus = "Message could not be sent"; } _log.info(strStatus); } catch (Exception e) { _log.log(Level.SEVERE,e.getMessage()); } } } //tutorial source: http://gaejexperiments.wordpress.com/2009/09/25/gaej-xmpp-and-rolling-your-own-agent/ **************************************************************************************************** The chat client tutorial of the book is: **************************************************************************************************** / ******************************************************************************* * Copyright (c) 2005 Jean-Michel Lemieux, Jeff McAffer and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Hyperbola is an RCP application developed for the book * Eclipse Rich Client Platform - * Designing, Coding, and Packaging Java Applications * See http://eclipsercp.org * * Contributors: * Jean-Michel Lemieux and Jeff McAffer - initial API and implementation *******************************************************************************/ package smack.testing; import org.eclipse.equinox.app.IApplication; import org.eclipse.equinox.app.IApplicationContext; import org.jivesoftware.smack.Chat; import org.jivesoftware.smack.MessageListener; import org.jivesoftware.smack.XMPPConnection; import org.jivesoftware.smack.XMPPException; import org.jivesoftware.smack.packet.Message; /** * This class controls all aspects of the application's execution */ public class Application implements IApplication, MessageListener { public Object start(IApplicationContext context) throws Exception { XMPPConnection con = new XMPPConnection("eclipsercp.org"); try { con.connect(); con.login("reader", "secret", Long.toString(System.currentTimeMillis())); Chat chat = con.getChatManager().createChat("[email protected]", this); chat.sendMessage("Hi There!"); Thread.sleep(5000); } catch (XMPPException e) { e.printStackTrace(); } finally { con.disconnect(); } return IApplication.EXIT_OK; } public void stop() { // TODO Auto-generated method stub } public void processMessage(Chat chat, Message message) { System.out.println("Returned message: " + (message == null ? "<timed out>" : message.getBody())); } } **************************************************************************************************** -- You received this message because you are subscribed to the Google Groups "Google App Engine" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/google-appengine?hl=en.
