We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexDiscussionExhibition › Google talk speaking to Processing - Easy!
Page Index Toggle Pages: 1
Google talk speaking to Processing - Easy! (Read 1596 times)
Google talk speaking to Processing - Easy!
Apr 5th, 2010, 8:15pm
 
Hey

We needed to do some remote control of Processing, and thought Google Talk (xmpp) would be great. Turns out communicating with Processing this way is very very easy:

It is really easy to do, using the Smack API. Here is how.

- Download the Smack API
- Make a new sketch in Processing
- Add smack.jar and smackx.jar from the Smack API (Sketch -> Add File…)

Read more, and get the source code here:
http://cerulean.dk/words/?page_id=91

(...aaand now you can click the link, because I have posted 5 dummy posts to be allowed to make links)

Regards
Christian Liljedahl
Re: Google talk speaking to Processing - Easy!
Reply #1 - Apr 6th, 2010, 12:48am
 
Nice idea for remote controlling your sketch. Well done!
Re: Google talk speaking to Processing - Easy!
Reply #2 - Apr 6th, 2010, 4:04am
 
Google talk is using xmpp, so this works with Jabber and all of the other xmpp-combatible im systems out there.
Re: Google talk speaking to Processing - Easy!
Reply #3 - Apr 6th, 2010, 4:47am
 
Just posting the code here too, for your convenience
(Code updated 8. april 2010)

Quote:
/**
  Receiving data from Google Talk
  Using the Smack API - http://www.igniterealtime.org/projects/smack/index.jsp
  
  Example by Christian Liljedahl, 6. april 2010

  Add smack.jar and smackx.jar to your project Sketch -> Add file...  

*/

int redColor = 255;
String FromGoogleTalk = "";

// newChat has to be declared global. If not, the MessageListener will time out 
after 30 seconds. Processing does this, for some reason. 

Chat newChat;

void OpenChatConnection(){
  // This is the connection to google talk. If you use jabber, put other stuff in here.
  ConnectionConfiguration config = new ConnectionConfiguration("talk.google.com", 5222, "gmail.com");
        //config.setSASLAuthenticationEnabled(true);

  XMPPConnection connection = new XMPPConnection(config);
  try {
    connection.connect();
  } 
  catch (XMPPException e1) {
  }

  try {

    // This is the username and password of the chat client that is to run within Processing.  
    // Google password has to be of _strong_ quality to work    
    connection.login("processing_clientusername@gmail.com", "password");
    //connection.login("inside_processing_username@gmail.com", "yourpassword");
  } 
  catch (XMPPException e1) {
    // would probably be a good idea to put some user friendly action here.
    e1.printStackTrace(); 
  }

  // It would be pretty to do some sort of test here, to make sure we are connected.
  ChatManager chatmanager = connection.getChatManager();

  // Eventhandler, to catch incoming chat events
  newChat = chatmanager.createChat("useryouwanttolistento@gmail.com", new MessageListener() {
    public void processMessage(Chat chat, Message message) {
      // Here you do what you do with the message
      FromGoogleTalk = message.getBody();
      // Process commands
      println(FromGoogleTalk);
    }
   }
  );

}

void setup() {
  size(200, 200);
  noStroke();
  background(0);

  OpenChatConnection();
}

void draw() {
    fill(redColor,100 ,100);
    text(FromGoogleTalk, 15, 30);      
    
}

Re: Google talk speaking to Processing - Easy!
Reply #4 - Apr 6th, 2010, 5:10am
 
And.. for those of you who wonder how to make nicely colored Processing code in the Discourse, this is how to do it:

  • In Processing, select Edit > Copy for Discourse
  • Paste it into your message


I had a hard time finding this, because I looked for it in the forum. This is what I searched for:
Syntax highlighting of processing code


Page Index Toggle Pages: 1