亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

線程中沒有實例化ConnectionManager對象

線程中沒有實例化ConnectionManager對象吧?通過構造者模式返回的config沒有被使用

正在回答

2 回答

對應著我的寫,就可以了。

0 回復 有任何疑惑可以回復我~


private ConnectionConfig mConfig;
private WeakReference<Context> mContext;
private NioSocketConnector mConnection;
private IoSession mSession;
private InetSocketAddress mAddress;

public ?ConnectionManager(ConnectionConfig config){
? ?this.mConfig = config;
? ?this.mContext = new WeakReference<>(config.getContext());
? ?init();
}

private void init() {
? ?mAddress = new InetSocketAddress(mConfig.getIp(),mConfig.getPort());
? ?mConnection = new NioSocketConnector();
? ?mConnection.getSessionConfig().setReadBufferSize(mConfig.getReadBufferSize());
? ?mConnection.getFilterChain().addLast("logger",new LoggingFilter());
? ?mConnection.getFilterChain().addLast("codec",new ProtocolCodecFilter(new ObjectSerializationCodecFactory()));
? ?mConnection.setHandler(new DefaultHandler(mContext.get()));
? ?mConnection.setDefaultRemoteAddress(mAddress);
}



/**
* 外層調用取得與服務器的連接
* @return
*/
public boolean connect(){
? ?Log.e("tag", "準備連接");
? ?try{
? ? ? ?ConnectFuture future = mConnection.connect();
? ? ? ?future.awaitUninterruptibly();
? ? ? ?mSession = future.getSession();
? ? ? ?SessionManager.getInstance().setSeesion(mSession);

? ?}catch (Exception e){
? ? ? ?e.printStackTrace();
? ? ? ?Log.e("tag", "連接失敗");
? ? ? ?return false;
? ?}

? ?return mSession == null ? false : true;
}

/**
* 斷開連接的方法
*/
public void disConnection(){

? ?mConnection.dispose();//Dispose后,對象都不存在了
? ?mConnection = null;
? ?mSession ? ?= null;
? ?mAddress ? ?= null;
? ?mContext ? ?= null;

}

0 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消

線程中沒有實例化ConnectionManager對象

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號