public void GetSessionID(string ip, int port, string skey) { GetSessionArg arg = new GetSessionArg(); { arg.sip = ip; arg.iport = port; arg.skey = skey; arg.iserverid = 0; arg.auth = 0; } StartCoroutine("_GetSession", arg); }
private IEnumerator _GetSession(GetSessionArg arg) { WWWForm form = new WWWForm(); form.AddField("passport", arg.skey); form.AddField("serverid", arg.iserverid); form.AddField("auth", arg.auth); WWW www = new WWW(string.Format("http://{0}:{1}/session/get", arg.sip, arg.iport), form); while (!www.isDone) { yield return(0); } if (string.IsNullOrEmpty(www.error)) { string sJson = www.text; LitJson.JsonData jsondata = LitJson.JsonMapper.ToObject(sJson); int result = int.Parse(jsondata["result"].ToString()); if (result == 0) { string sessionid = jsondata["sessionid"].ToString(); string serverip = jsondata["serverip"].ToString(); int serverport = int.Parse(jsondata["serverport"].ToString()); GameRoot.NotifyGetSession(sessionid, serverip, serverport); m_loadStatus = ELoadStatus.End; } else { Debug.LogError("Get SessionID error, result = " + result); m_sError = sJson; m_loadStatus = ELoadStatus.Error; } } else { Debug.LogError("Get SessionID error!"); m_sError = www.error; m_loadStatus = ELoadStatus.Error; } }