public IEnumerator ReConnectTCP(TCPWorkInterface inter) { while (!inter.Vaild()) // 异常情况则不断检测重新连接 { StartTCPWorker(); yield return(new WaitForSeconds(5.0f)); } }
static void OnConnSucFunc() { Debug.Log("OnConnSucFunc"); if (TCPWorkInterface.onConSucHandler != null) { TCPWorkInterface.onConSucHandler(); } }
/// <summary> /// 连接 /// </summary> /// <param name="state"></param> private static void OnConnectState(ConnectState state) { Debug.Log("Connect Status"); TCPWorkInterface networkInterface = state.netWorkInterface; networkInterface.Connecting = false; if (state.success) { //创建接收线程和发送线程 networkInterface.StartTCPWorker(); OnConnSucFunc(); //启动协程判断网络是否断开(暂时备用 ) TCPNetWork.GetInstance().StartCoroutine(CheckNetStateLoop(state)); } else { networkInterface.Close(); Debug.Log("connect error :" + state.success); // 增加检测重连5s一次 } }
private void Awake() { MsgPool = new MessagePool(); inter = new TCPWorkInterface(); }