private IEnumerator CoroNetworkState(float timeout) { timeout += Time.realtimeSinceStartup; for (; ;) { yield return(null); if (timeout < Time.realtimeSinceStartup || m_NC.error != null) { m_NC.Close(); OnDisconnected(); yield break; } if (m_NC.Connected) { NetworkMgr.Log("Connected"); // 清空前一次连接的消息 m_Msgs.Clear(); OnConnected(); break; } } for (; ;) { if (!m_NC.Connected) { OnDisconnected(); break; } yield return(null); } }
static int GetHttpHandler(IntPtr L) { L.ChkArgsCount(2); ZFrame.NetEngine.NetworkMgr obj = (ZFrame.NetEngine.NetworkMgr)L.ChkUnityObjectSelf(1, "ZFrame.NetEngine.NetworkMgr"); var arg0 = L.ToLuaString(2); ZFrame.NetEngine.HttpHandler o = obj.GetHttpHandler(arg0); L.PushLightUserData(o); return(1); }
public void Connect(string host, int port, float timeout) { if (m_NC != null) { NetworkMgr.Log("Connect -> {0}:{1}", host, port); if (m_Coro != null) { StopCoroutine(m_Coro); } m_NC.Connect(host, port); m_Coro = StartCoroutine(CoroNetworkState(timeout)); } }
//Post Form private IEnumerator CoroHttpPost(string tag, string uri, string param, WWWForm wf, Dictionary <string, string> headers, float timeout) { float time = Time.realtimeSinceStartup + timeout; if (!string.IsNullOrEmpty(param)) { uri = uri + "?" + param; } NetworkMgr.Log("WWW Post: {0}\n{1}", uri, wf.ToString()); using (WWW www = new WWW(uri, wf)) { while (!www.isDone) { if (time < Time.realtimeSinceStartup) { break; } yield return(null); } LogMgr.D("{0}", www.text); HandleHttpResp(www, tag); } }
//Post byte private IEnumerator CoroHttpPost(string tag, string uri, string param, byte[] postData, Dictionary <string, string> headers, float timeout) { float time = Time.realtimeSinceStartup + timeout; if (!string.IsNullOrEmpty(param)) { uri = uri + "?" + param; } NetworkMgr.Log("WWW Post: {0}\n{1}", uri, System.Text.Encoding.UTF8.GetString(postData)); using (WWW www = new WWW(uri, postData, headers)) { while (!www.isDone) { if (time < Time.realtimeSinceStartup) { break; } yield return(null); } HandleHttpResp(www, tag); } }
private IEnumerator CoroHttpGet(string tag, string uri, string param, float timeout) { float time = Time.realtimeSinceStartup + timeout; if (!string.IsNullOrEmpty(param)) { uri = uri + "?" + param; } NetworkMgr.Log("WWW Get: {0}", uri); using (WWW www = new WWW(uri)) { while (!www.isDone) { if (time < Time.realtimeSinceStartup) { break; } yield return(null); } HandleHttpResp(www, tag); } }