我有一个名为conexao的类,它管理我到服务器的socket.io连接,我意识到我在一些活动中需要它。
把它定为一节课有错吗?
conexao.java文件:
package com.example.group;
import android.app.Activity;
import android.util.Log;
import android.widget.TextView;
import io.socket.client.IO;
import io.socket.client.Socket;
public class Conexao {
private static Conexao instance;
public String host = "http://192.168.0.117:8090";
Socket socket;
public synchronized static Conexao getInstance() {
if (instance == null) {
try {
instance = new Conexao();
}catch (Exception e){
}
}
return instance;
}
public Conexao() throws URISyntaxException {
socket = IO.socket(host);
}
public void open(){
socket.connect();
}
public void close(){
socket.disconnect();
}
}
暂无答案!
目前还没有任何答案,快来回答吧!