Than
Than

Reputation: 446

Android implementation for client Socket.io compatible with version 1.0 - Beginner

thanks for read my question. (pleaase apologize my bad english)

I'm trying to develop a simple android prototype using socket.io. i've got a server node.js with socket.io (is working), and now i'm develop the client side (there is the problem).

I've download the zip on : https://github.com/nkzawa/socket.io-client.java On Eclipse, i have do a right click on my projet/ Build Path / Add external Archive and i selected the downloaded file. The client code :

package com.example.temp_test;

import java.net.URISyntaxException;



import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        final Socket socket;
        try {
            socket = IO.socket("X.X.X.X:8080");
            socket.on(Socket.EVENT_CONNECT, new Emitter.Listener() {

                  @Override
                  public void call(Object... args) {
                    socket.emit("message", "hi");
                    socket.disconnect();
                  }

                }).on("event", new Emitter.Listener() {

                  @Override
                  public void call(Object... args) {}

                }).on(Socket.EVENT_DISCONNECT, new Emitter.Listener() {

                  @Override
                  public void call(Object... args) {}

                });
                socket.connect();
        } catch (URISyntaxException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        setContentView(R.layout.activity_main);
    }

    @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;
    }

}

Of course X.X.X.X is an IP adress. So now i've got some red lines because eclipse doesn't find the IO class.

I'm already tried tutorials, like this : Java implementation for client Socket.io compatible with version 1.0 (i've got some crash), many other are too old or not compatible 1.0.

I'm juste a beginner with on socket.io android. So if someone can help me, i just want the way to install good packages without crash, that will be very appreciate and i will can do the rest myself.

Thanks in advance

Upvotes: 1

Views: 2441

Answers (2)

Esther
Esther

Reputation: 78

I just saw your post, it's an old post, but probably my answer could help to other beginners like me.

The socket.io.client needs the engine.io-client library. The url of the source code is here: https://github.com/nkzawa/engine.io-client.java

Upvotes: 0

Wahib Ul Haq
Wahib Ul Haq

Reputation: 4385

I am also going through the same issue. I tried gottox but we also have v1.0 on nodejs server so it didn't work out. I just found that https://github.com/koush/ion is a more simple and stable approach to implement socketio client on Android. I'll try this tomorrow and maybe you can also try and we can share our findings. This offers jar file so at least you don't have to go through the maven path.

Upvotes: 1

Related Questions