简体   繁体   English

客户端Socket.io的Android实现与1.0版兼容-入门

[英]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. 我正在尝试使用socket.io开发一个简单的android原型。 i've got a server node.js with socket.io (is working), and now i'm develop the client side (there is the problem). 我有一个带有socket.io的服务器node.js(正在运行),现在我在开发客户端(有问题)。

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. 我已经在以下位置下载了zip文件: https : //github.com/nkzawa/socket.io-client.java在Eclipse上,我右键单击了我的projet / Build Path / Add external Archive,然后选择了下载的文件。 The client code : 客户端代码:

package com.example.temp_test; 包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 XXXX is an IP adress. 当然XXXX是IP地址。 So now i've got some red lines because eclipse doesn't find the IO class. 现在,我有了一些红线,因为eclipse找不到IO类。

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. 我已经尝试过这样的教程: 客户端Socket.io的Java实现与版本1.0兼容 (我有些崩溃),许多其他版本太旧或不兼容1.0。

I'm juste a beginner with on socket.io android. 我只是一个关于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 提前致谢

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. 我试过了gottox,但是在nodejs服务器上也有v1.0,所以没有解决。 I just found that https://github.com/koush/ion is a more simple and stable approach to implement socketio client on Android. 我刚刚发现https://github.com/koush/ion是在Android上实现socketio客户端的更简单,更稳定的方法。 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. 这提供了jar文件,因此至少您不必通过Maven路径。

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. socket.io.client需要engine.io-client库。 The url of the source code is here: https://github.com/nkzawa/engine.io-client.java 源代码的URL在这里: https : //github.com/nkzawa/engine.io-client.java

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM