Unity Http短连接

来源:互联网 发布:在淘宝买手机靠谱吗 编辑:程序博客网 时间:2024/05/16 18:18
            //需要发送的消息协议            
            WWW www_instance = new WWW(url, message);
            //时间函数单位毫秒
            Stopwatch sw = new Stopwatch();
            sw.Start();

            byte[] ty = new byte[0];

            //检测是否加载完成

            while (!www_instance.isDone)
            {
                if (sw.ElapsedMilliseconds >= 1000)
                {
                    if (www_instance.error != null)
                    {
                        Debug.Log("连接超时-----请稍后");
                        sw.Stop();
                        break;
                    }
                    else
                    {
                        if (sw.ElapsedMilliseconds >= 4500)
                        {
                            ty = www_instance.bytes;
                            if (ty.Length == 0)
                            {
                                Debug.Log("连接超时---- - 请稍后,没有返回数据");
                                sw.Stop();
                                break;
                            }
                        }
                    }
                }
            }
            sw.Stop();
            Debug.LogError(sw.ElapsedMilliseconds);

            ty = www_instance.bytes;

            //消息解析

            HttpHand.message(ty);    
0 0