title: Successfully run Socket.IO Android Project with NodeJS
body: <p>I've managed to get a Socket.IO/Android project to compile and now I'm trying to get it to communicate with Socket.IO on a NodeJS server. I placed the project on my Drop Box here:</p>
  
  <p><a href="https://dl.dropboxusercontent.com/u/86164338/socketIOAndroid.zip" rel="nofollow">https://dl.dropboxusercontent.com/u/86164338/socketIOAndroid.zip</a></p>
  
  <p>Everything compiles and runs but I see no output from NodeJS.</p>
  
  <p>This is based on:
  <a href="https://github.com/Gottox/socket.io-java-client" rel="nofollow">https://github.com/Gottox/socket.io-java-client</a></p>
  
  <p>Note that there are instructions on compiling the Java code and copying the jar file to the libs folder:</p>
  
  <blockquote>
    <p>git clone git://github.com/Gottox/socket.io-java-client.git<br />
    cd socket.io-java-client<br />
    ant jar mv jar/socketio.jar<br />
    /path/to/your/libs/project <br /></p>
  </blockquote>
  
  <p>Any help is greatly appreciated.</p>
  
  <p>Java Code:</p>
  
  <pre><code>package com.depictlabs.testsockets03;
  
  import java.net.MalformedURLException;
  import java.net.URI;
  
  import org.json.JSONObject;
  
  
  import io.socket.SocketIO;
  import io.socket.IOCallback;
  import io.socket.IOAcknowledge;
  import io.socket.SocketIOException;
  
  import android.os.Bundle;
  import android.app.Activity;
  import android.view.Menu;
  
  import org.json.JSONException;
  import org.json.JSONObject;
  
  public class MainActivity extends Activity {
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          SocketIO socket;
  
          try{
              System.out.println("Initializing Connection.");
  
              socket = new SocketIO("http://localhost:3000/");
              socket.connect
                  (
                      new IOCallback(){
                          @Override
                          public void onMessage(JSONObject json, IOAcknowledge ack) {
                              try {
                                  System.out.println("Server said:" + json.toString(2));
                              } catch (JSONException e) {
                                  e.printStackTrace();
                              }
                          }
  
                          @Override
                          public void onMessage(String data, IOAcknowledge ack) {
                           System.out.println("Server said: " + data);
                          }
  
                          @Override
                          public void onError(SocketIOException socketIOException) {
                              System.out.println("an Error occured");
                              socketIOException.printStackTrace();
                          }
  
                          @Override
                          public void onDisconnect() {
                              System.out.println("Connection terminated.");
                          }
  
                          @Override
                          public void onConnect() {
                           System.out.println("Connection established");
                          }
  
                          @Override
                          public void on(String event, IOAcknowledge ack, Object... args) {
                              System.out.println("Server triggered event '" + event + "'");
                          }
                      }
                  );
  
              try {
                  // This line is cached until the connection is established.
                  System.out.println("Sending message to server.");
                  socket.send("user message");
              } catch (Exception e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
              }
          } catch (MalformedURLException e1) {
              e1.printStackTrace();
          }
      }
  
      @Override
      public boolean onCreateOptionsMenu(Menu menu) {
          // Inflate the menu; this adds items to the action bar if it is present.
          getMenuInflater().inflate(R.menu.main, menu);
          return true;
      }
  }
  </code></pre>
  
  <p>NodeJS Code:</p>
  
  <pre><code>var http = require('http')
  , io   = require('socket.io');
  
  var app = http.createServer();
  app.listen(3000);
  
  console.log('Server running at http://127.0.0.1:3000/');
  
  // Socket.IO server
  var io = io.listen(app)
  , nicknames = {};
  
  io.sockets.on('connection', function (socket) {
      socket.on('user message', function (msg) {
          console.log('Server running at http://127.0.0.1:3000/');
          socket.broadcast.emit('user message', {user: socket.nickname, message: msg.message});
      });
  
      socket.on('nickname', function (nick, fn) {
          console.log('Server running at http://127.0.0.1:3000/');
          nickname = nick.nickname;
          if (nicknames[nickname]) {
              fn(true);
          } else {
              fn(false);
              nicknames[nickname] = socket.nickname = nickname;
              socket.broadcast.emit('announcement', {user: nickname, action: 'connected'});
              io.sockets.emit('nicknames', nicknames);
          }
      });
  
      socket.on('disconnect', function () {
          console.log('Server running at http://127.0.0.1:3000/');
          if (!socket.nickname) return;
  
          delete nicknames[socket.nickname];
          socket.broadcast.emit('announcement', {user: socket.nickname, action: 'disconected'});
          socket.broadcast.emit('nicknames', nicknames);
      });
  });
  </code></pre>