public class ConnectionManager {
public interface SocketInitializeListener {
public void onSuccess();
public void onError(String e);
}
public static ConnectionManager instance = null;
private static Object key = new Object();
public static ConnectionManager getInstance(){
if(instance==null){
synchronized (key) {
if(instance==null) {
instance = new ConnectionManager();
reyurn instance;
}
}
}
return instance;
}
private Socket connection;
public void setConnection(Socket connection) {
this.connection = connection;
}
public Socket getConnection() {
return connection;
}
public void initConnection(final String ip,final int port , final SocketInitializeListener callBack) {
(new Thread(){
private boolean isConnect = false;
@Override
public void run() {
try{
connection = new Socket(ip, port);
isConnect = true;
}catch(Exception e){ callBack.onError(e.getMessage().toString()); isConnect = false; }
finally{
if(isConnect)
callBack.onSuccess();
}
}
}).start();
}
}
// 소스의 간단한설명과 주석좀 달아주세요 제 상태는 이제 공부시작하는 초짜에요..