예제 #1
0
        private void onReceivedNotify(int seq, int cmd, byte[] data)
        {
            Log.w("Network", string.Concat(new object[] { "notify received, cmd=", (CmdConst)cmd, ", datalen=", data.Length }));
            int num3 = cmd;

            if (num3 <= 0x18)
            {
                switch (num3)
                {
                case 5:
                case 0x18:
                    if ((data != null) && (data.Length >= 4))
                    {
                        int offset = 0;
                        int num2   = Util.readInt(data, ref offset);

                        EventCenter.postEvent(EventConst.ON_NETSCENE_NOTIFY_SYNC_REQ, num2, null);

                        return;
                    }
                    EventCenter.postEvent(EventConst.ON_NETSCENE_NOTIFY_SYNC_REQ, null, null);
                    return;

                case 6:
                case 8:
                case 9:
                case 10:
                case 11:
                    return;

                case 7:
                    EventCenter.postEvent(EventConst.SYS_MSG_EXIT, null, null);
                    return;

                case 12:
                    Connector.close();
                    return;
                }
            }
            else
            {
                switch (num3)
                {
                case 0x3d:
                    // EventCenter.postEvent(EventConst.ON_VOIP_NOTIFYSYNC, data, null);
                    break;

                case 318:
                    // EventCenter.postEvent(EventConst.ON_VOIP_NOTIFYSYNC, data, null);
                    Log.w("Network", string.Concat(new object[] { "encode notify received, cmd=", (CmdConst)cmd, ", data", Util.byteToHexStr(data) }));
                    decodeNotifyData(data);
                    break;

                case 0x48:
                    ServerBulletin.onRecvBulletin(data);
                    return;

                default:
                    if (num3 == 120)
                    {
                        //EventCenter.postEvent(EventConst.ON_VOIP_NOTIFYINVITE, data, null);
                    }
                    return;
                }
            }
        }
예제 #2
0
        private void onRecvHttpCallback(IAsyncResult asynchronousResult)
        {
            Action             action  = null;
            Action             action2 = null;
            HttpRequestContext context = (HttpRequestContext)asynchronousResult.AsyncState;

            try
            {
                HttpWebRequest mRequest = context.mRequest;
                context.mResponse = (HttpWebResponse)mRequest.EndGetResponse(asynchronousResult);

                ServerBulletin.onRecvBulletin(context.mResponse.Headers["WXBT"]);
                // Stream responseStream = context.mResponse.GetResponseStream();

                Log.w("Network", "http return head ,statuscode =  " + context.mResponse.StatusCode.ToString() + "http seq " + httpseq);//get_StatusCode());
                Stream ms = context.mResponse.GetResponseStream();

                //    using (var ms = context.mResponse.GetResponseStream())
                //      {
                //  using (var responseStream = new MemoryStream())
                //  {
                //responseStream.(ms);
                var       responseStream = new MemoryStream();
                const int bufferLength   = 1024 * 10;
                int       actual;
                byte[]    buffers = new byte[bufferLength];
                while ((actual = ms.Read(buffers, 0, bufferLength)) > 0)
                {
                    responseStream.Write(buffers, 0, actual);
                }
                responseStream.Position = 0;
                //...
                // }
                //   }


                int    newSize = ((int)responseStream.Length) + 0x2000;
                byte[] buffer  = new byte[newSize];
                int    len     = responseStream.Read(buffer, 0, (int)responseStream.Length);
                int    num3    = 0;
                context.setProgress(len);
                do
                {
                    num3 = responseStream.Read(buffer, len, newSize - len);
                    if (num3 > 0)
                    {
                        len += num3;
                        if ((newSize - len) < 0x2000)
                        {
                            newSize += 0x2000;
                            Array.Resize <byte>(ref buffer, newSize);
                        }
                        context.setProgress(len);
                    }
                }while (num3 > 0);
                context.mOutputLength = len;
                context.mBufferOutput = buffer;
                context.mStatus       = 2;
                if (this.rspCallback != null)
                {
                    if (action == null)
                    {
                        // action = () =>
                        this.rspCallback(context.mBufferOutput);
                    }
                    //Deployment.get_Current().get_Dispatcher().BeginInvoke(action);
                }
                //context.mResponse.Close();
                responseStream.Dispose();
            }
            catch (Exception exception)
            {
                Log.e("Network", "http.onRecvHttpCallback failed: " + exception.Message);
                context.mStatus = 2;
                context.release();
                if (this.rspCallback != null)
                {
                    if (action2 == null)
                    {
                        //action2 = () =>
                        this.rspCallback(null);
                    }
                    //Deployment.get_Current().get_Dispatcher().BeginInvoke(action2);
                }
            }
        }