예제 #1
0
 public void init()
 {
     SFUtils.log("正在连接GameServer...");
     m_sendQueue      = new Queue <SFBaseRequestMessage>();
     m_recvQueue      = new Queue <string>();
     dispatcher       = new SFEventDispatcher(this);
     m_client         = new SFTcpClient();
     m_ping           = -1;
     m_heartbeatTimer = SFCommonConf.instance.heatbeatInterval;
     m_client.init(SFCommonConf.instance.serverIp, SFCommonConf.instance.serverPort, onRecvMsg, ret =>
     {
         if (ret == 0)
         {
             SFUtils.log("连接GameServer成功");
         }
         else
         {
             SFUtils.logWarning("连接GameServer失败");
         }
         dispatcher.dispatchEvent(SFEvent.EVENT_NETWORK_READY, new SFSimpleEventData(ret));
     });
     m_client.dispatcher.addEventListener(this, SFEvent.EVENT_NETWORK_INTERRUPTED, e =>
     {
         dispatcher.dispatchEvent(e);
     });
     dispatcher.addEventListener(this, SFResponseMsgSocketHeartbeat.pName, onHeartbeat);
 }
예제 #2
0
 public void uninit()
 {
     if (m_client != null)
     {
         m_client.uninit();
         m_client = null;
     }
     if (m_sendQueue != null)
     {
         m_sendQueue = null;
     }
     if (m_recvQueue != null)
     {
         m_recvQueue = null;
     }
     if (dispatcher != null)
     {
         dispatcher.removeAllEventListeners();
     }
 }