예제 #1
0
        //u3d
        IEnumerator testU3d(int count)
        {
            var w1 = new WWW("http://www.baidu.com");

            yield return(w1);

            if (!w1.isDone)
            {
                CothreadHub.Log("[testU3d] www error");
            }
            else
            {
                CothreadHub.Log("[testU3d] www ok: size:" + w1.text.Length.ToString());
            }

            var result = new CothreadResult <bool>();
            var u1     = UnityHub.Active.StartCoroutine(_u3dCoroutine1(result));

            yield return(u1);

            if (result.Result.Equals(true))
            {
                CothreadHub.Log("[testU3d]StartCoroutine ok");
            }
            else
            {
                CothreadHub.Log("[testU3d]StartCoroutine error");
            }
        }
예제 #2
0
        //utf8 encoding
        public IEnumerator RecvString(CothreadSocketRecvData recvData, CothreadResult <string> result)
        {
            if (!Connected)
            {
                yield break;
            }
            yield return(Recv(recvData));

            result.Result = System.Text.Encoding.UTF8.GetString(recvData.Data, 0, recvData.Length);
        }
예제 #3
0
        IEnumerator testSock1(int i)
        {
            string stri = i.ToString();

            CothreadHub.Log("testSock:" + stri);
            CothreadTimeout timeout = CothreadTimeout.NewWithStart(5);
            CothreadSocket  sock    = new CothreadSocket();

            yield return(sock.Connect("192.168.0.210", 81));             //web server

            //yield return sock.Connect("www.baidu.com", 80);  //www.baidu.com
            //yield return sock.Connect("115.239.210.27", 80);  //www.baidu.com
            //yield return hub.Sleep(rt);
            //CothreadHub.Log(stri + "-socket connected:" + sock.Connected);

            yield return(sock.SendString("GET / HTTP/1.0\n\n"));

            //CothreadHub.Log(stri + "-Send ok");
            var recvData = new CothreadSocketRecvData(2048);
            var result   = new CothreadResult <string>();

            yield return(hub.Sleep(1000));

            yield return(sock.RecvString(recvData, result));

            string s1 = (string)result.Result;

            if (string.IsNullOrEmpty(s1))
            {
                CothreadHub.Log("testSock(" + stri + ") error" + "-passTime:" + timeout.PassTime.ToString());
            }
            else
            {
                CothreadHub.Log("testSock(" + stri + ") ok:" + s1.Length.ToString() + "  data:" + s1.Substring(0, Math.Min(500, s1.Length)));
            }
            try {
                timeout.Cancel(true);
            } catch (CothreadTimeoutError) {
                CothreadHub.Log(stri + "-testSock timeout");
            } finally {
                sock.Close();
            }
        }
예제 #4
0
        IEnumerator _u3dCoroutine1(CothreadResult <bool> result)
        {
            yield return(new WaitForSeconds(1));

            result.Result = true;
        }