Beispiel #1
0
        /// <summary>
        /// 发送给服务器的数据
        /// </summary>
        /// <param name="_scriptName">服务器端,协议类名</param>
        /// <param name="_netForm">发送给服务器的json数据</param>
        /// <param name="respondFunction">服务器返回给客户端的数据</param>
        public void RequestOfSocket(string _scriptName, DMNetForm _netForm, RespondOfHttpJD respondFunction)
        {
            string jdStr = JsonMapper.ToJson(_netForm.GetSendObj);
            string jd    = _scriptName + jdStr + "\r\n";

            Debug.LogError(jd);
            byte[] strBytes = Encoding.UTF8.GetBytes(jd);
            ReceiveMessage(strBytes, respondFunction);
        }
Beispiel #2
0
        public void RequestOfHttp(string _scriptName, DMNetForm _netForm, RespondOfHttpJD respondFunction)
        {
            string jdStr = JsonMapper.ToJson(_netForm.GetSendObj);
            string jddd  = _scriptName + jdStr + "\r\n";

            Debug.LogError(jddd);
            byte[] strBytes = Encoding.UTF8.GetBytes(jddd);
            StartCoroutine(RequestServer(strBytes, respondFunction));
        }
Beispiel #3
0
 /// <summary>
 /// 向服务器发送消息,并接收来自服务器的回复消息
 /// </summary>
 /// <param name="_strBytes">发送给服务器的字节</param>
 /// <param name="_respondFunction">服务器返回给客户端的回调数据</param>
 void ReceiveMessage(byte[] _strBytes, RespondOfHttpJD _respondFunction)
 {
     try
     {
         this.ClientSocket.Send(_strBytes);
         _respondFunction?.Invoke(AsynRecive(ClientSocket));
     }
     catch (Exception ex)
     {
         Debug.LogError("写Error日志" + ex.ToString());
     }
 }
Beispiel #4
0
        private IEnumerator <WWW> RequestServer(byte[] _strBytes, RespondOfHttpJD _respondFunction)
        {
            using (WWW www = new WWW("http://127.0.0.1:2017", _strBytes))
            {
                yield return(www);

                if (www.error == null)
                {
                    string wwwStr = www.text;
                    Debug.Log("wwwStr:" + wwwStr);
                    JsonData jd2 = JsonMapper.ToObject(wwwStr.Replace("[[", "[{").Replace("]]", "}]"));
                    JsonData jd  = JsonMapper.ToObject(wwwStr);
                    _respondFunction?.Invoke(jd);
                }
                else
                {
                    Debug.Log(www.error);
                }
            }
        }