예제 #1
0
        internal override bool Connect(string serverAddress, string appID)
        {
            if (this.peerConnectionState != PeerBase.ConnectionStateValue.Disconnected)
            {
                if (this.debugOut >= DebugLevel.WARNING)
                {
                    this.Listener.DebugReturn(DebugLevel.WARNING, "Connect() called while peerConnectionState != Disconnected. Nothing done.");
                }
                return(false);
            }
            if (string.IsNullOrEmpty(serverAddress) || !serverAddress.StartsWith("http", true, (CultureInfo)null))
            {
                this.Listener.DebugReturn(DebugLevel.ERROR, "Connect() with RHTTP failed. ServerAddress must include 'http://' or 'https://' prefix. Was: " + serverAddress);
                return(false);
            }
            this.outgoingStream = new MemoryStream(PeerBase.outgoingStreamBufferSize);
            this.Reset();
            this.peerConnectionState = PeerBase.ConnectionStateValue.Connecting;
            this.ServerAddress       = serverAddress;
            this.UrlParameters       = "?init&cid=";
            this.UrlParameters      += (string)(object)this._challengId;
            if (appID == null)
            {
                appID = "NUnit";
            }
            HttpBase3 httpBase3 = this;
            string    str       = httpBase3.UrlParameters + "&app=" + appID;

            httpBase3.UrlParameters = str;
            this.UrlParameters     += "&clientversion=4.0.0.0";
            this.UrlParameters     += "&protocol=GpBinaryV16";
            this.lastPingTimeStamp  = (long)this.GetLocalMsTimestamp();
            this.Request((byte[])null, this.UrlParameters, HttpBase3.MessageType.CONNECT);
            return(true);
        }
예제 #2
0
 private void _webExceptionHandler(HttpBase3.AsyncRequestState state, WWW request)
 {
     if (state.IsDisconnect)
     {
         return;
     }
     if ((this.peerConnectionState != PeerBase.ConnectionStateValue.Disconnecting || this.peerConnectionState != PeerBase.ConnectionStateValue.Disconnected) && !state.restarting && this.debugOut >= DebugLevel.ERROR)
     {
         this.Listener.DebugReturn(DebugLevel.ERROR, string.Format("Request {0} for pid={1} cid={2} failed with error: {3}", (object)state.id, (object)this.HttpPeerID, (object)this._challengId, (object)request.error));
     }
     if (this.peerConnectionState == PeerBase.ConnectionStateValue.Connecting)
     {
         this.EnqueueErrorDisconnect(StatusCode.ExceptionOnConnect);
     }
     else
     {
         if (this.peerConnectionState != PeerBase.ConnectionStateValue.Connected)
         {
             return;
         }
         if (HttpBase3.gotIgnoreStatus(this.getResponseStatus(request)))
         {
             if (this.debugOut < DebugLevel.ALL)
             {
                 return;
             }
             this.Listener.DebugReturn(DebugLevel.ALL, "got statues which we ignore");
         }
         else
         {
             this.EnqueueErrorDisconnect(StatusCode.DisconnectByServer);
         }
     }
 }
예제 #3
0
        private static int _getStatusCodeFromResponse(byte[] response, HttpBase3 peer)
        {
            int num = 0;

            if (response.Length >= 4)
            {
                num = num | (int)response[0] << 24 | (int)response[1] << 16 | (int)response[2] << 8 | (int)response[3];
            }
            return(num);
        }
예제 #4
0
        private void _parseMessage(byte[] inBuff, BinaryReader br)
        {
            int length = inBuff.Length;

            using (br)
            {
                using (Stream baseStream = br.BaseStream)
                {
                    while (baseStream.Position != baseStream.Length)
                    {
                        switch (br.ReadByte())
                        {
                        case 251:
                            int count = HttpBase3._readMessageHeader(br) - 7;
                            if (count == -1)
                            {
                                if (this.debugOut < DebugLevel.ERROR)
                                {
                                    return;
                                }
                                this.Listener.DebugReturn(DebugLevel.ERROR, string.Format("Invalid message header for pid={0} cid={1} and message {2}", (object)this.HttpPeerID, (object)this._challengId, (object)SupportClass.ByteArrayToString(inBuff)));
                                return;
                            }
                            System.Diagnostics.Debug.Assert(count >= 2);
                            byte[] numArray = br.ReadBytes(count);
                            if (count < 2)
                            {
                                this.Listener.DebugReturn(DebugLevel.WARNING, string.Format("data len is to small. data {0}", (object)SupportClass.ByteArrayToString(inBuff)));
                            }
                            lock (this.incomingList)
                            {
                                this.incomingList.Add(numArray);
                                if (this.incomingList.Count % this.warningSize == 0)
                                {
                                    this.EnqueueStatusCallback(StatusCode.QueueIncomingReliableWarning);
                                    break;
                                }
                                break;
                            }

                        case 240:
                            this.ReadPingResponse(br);
                            break;

                        default:
                            this.Listener.DebugReturn(DebugLevel.WARNING, "Unknow response from server");
                            break;
                        }
                    }
                }
            }
        }
예제 #5
0
        private static int _getStatusCodeFromResponse(HttpWebResponse response, HttpBase3 peer)
        {
            int statusCode = 0;

            if (response.ContentLength >= 4L)
            {
                try
                {
                    BinaryReader binReader = new BinaryReader(response.GetResponseStream());
                    statusCode |= binReader.ReadByte() << 0x18;
                    statusCode |= binReader.ReadByte() << 0x10;
                    statusCode |= binReader.ReadByte() << 8;
                    statusCode |= binReader.ReadByte();
                }
                catch (Exception e)
                {
                    peer.Listener.DebugReturn(DebugLevel.ERROR, string.Format("Exception '{0}' happened during response status reading", e.Message));
                }
            }
            return(statusCode);
        }