コード例 #1
0
ファイル: UriEx.cs プロジェクト: OlegPalchyk/imBMW
        /// <summary>
        /// Indicates whether the string is well-formed by attempting to
        /// construct a URI with the string.
        /// </summary>
        /// <param name="uriString">A URI.</param>
        /// <param name="uriKind">The type of the URI in
        /// <paramref name="uriString"/>.</param>
        /// <returns>
        /// <itemref>true</itemref> if the string was well-formed in accordance
        /// with RFC 2396 and RFC 2732; otherwise <itemref>false</itemref>.
        /// </returns>
        public static bool IsWellFormedUriString(string uriString, UriKind uriKind)
        {
            try
            {               // If absolute Uri was passed - create Uri object.
                switch (uriKind)
                {
                case UriKind.Absolute:
                {
                    UriEx testUri = new UriEx(uriString);

                    if (testUri.IsAbsoluteUri)
                    {
                        return(true);
                    }

                    return(false);
                }

                case UriKind.Relative:
                {
                    UriEx testUri = new UriEx(uriString, UriKind.Relative);
                    if (!testUri.IsAbsoluteUri)
                    {
                        return(true);
                    }

                    return(false);
                }

                default: return(false);
                }
            }
            catch
            {
                return(false);
            }
        }
コード例 #2
0
        protected virtual void Dispose(bool disposing)
        {
            if (this.isDisposed)
                return;

            if (disposing)
            {
                // disconnect
                this.Disconnect();
                DateTime timeoutTime = DateTime.Now.AddSeconds(20);
                while (this.state != WebSocketState.Disconnected && DateTime.Now < timeoutTime)
                    Thread.Sleep(500);

                // kill thread
                this.runThreadLoop = false;
                this.runStateMachine.Set();
                this.stateMachineThread.Join(1000);

                // clear the message queue
                if (this.sendQueue != null)
                    this.sendQueue.Clear();

                // kill timer
                if (this.activityTimer != null)
                    this.activityTimer.Dispose();

                // cleanup streams
                if (this.socketStream != null)
                    this.socketStream.Close();

                // cleanup sockets
                if (this.socket != null)
                    this.socket.Close();
            }

            // set everything to null
            this.eventLock = null;
            this.sendLock = null;
            this.activityTimer = null;
            this.sendQueue = null;
            this.socket = null;
            this.socketStream = null;
            this.receiveBuffer = null;
            this.lastRcvdFrame = null;
            this.serverUri = null;
            this.loggerID = null;
            this.origin = null;
            this.subProtocol = null;
            this.extensions = null;
            this.securityKey = null;
            this.options = null;

            // make sure we don't dispose again
            this.isDisposed = true;
        }
コード例 #3
0
        /// <summary>
        /// Connect - Begins the asynchronous (non-blocking) connection process.
        /// </summary>
        /// <param name="serverUrl">Url of server to connect to.</param>
        public void Connect(string serverUrl)
        {
            if (this.State == WebSocketState.Initialized || this.State == WebSocketState.Disconnected)
            {
                try
                {
                    this.serverUri = new UriEx(serverUrl);

                    IPHostEntry hostEntry = Dns.GetHostEntry(this.serverUri.Host);
                    IPAddress ipAddress = hostEntry.AddressList[0];
                    this.serverEndpoint = new IPEndPoint(ipAddress, this.serverUri.Port);

                    // start the connection process
                    Logger.WriteDebug(this.loggerID, "Connecting to " + serverUrl + " ...");
                    this.state = WebSocketState.Connecting;
                    this.subState = SubState.OpenTcpConnection;
                    this.runStateMachine.Set();
                }
                catch (Exception ex)
                {
                    this.OnError(WSErrorCode.NativeError, ex.Message, ex.StackTrace);
                }
            }
        }
コード例 #4
0
ファイル: UriEx.cs プロジェクト: Injac/SocketIO.NetMF
		/// <summary>
		/// Indicates whether the string is well-formed by attempting to
		/// construct a URI with the string.
		/// </summary>
		/// <param name="uriString">A URI.</param>
		/// <param name="uriKind">The type of the URI in
		/// <paramref name="uriString"/>.</param>
		/// <returns>
		/// <itemref>true</itemref> if the string was well-formed in accordance
		/// with RFC 2396 and RFC 2732; otherwise <itemref>false</itemref>.
		/// </returns>
		public static bool IsWellFormedUriString(string uriString, UriKind uriKind)
		{
			try
			{   // If absolute Uri was passed - create Uri object.
				switch (uriKind)
				{
					case UriKind.Absolute:
						{
							UriEx testUri = new UriEx(uriString);

							if (testUri.IsAbsoluteUri)
							{
								return true;
							}

							return false;
						}

					case UriKind.Relative:
						{
							UriEx testUri = new UriEx(uriString, UriKind.Relative);
							if (!testUri.IsAbsoluteUri)
							{
								return true;
							}

							return false;
						}
					default: return false;
				}
			}
			catch
			{
				return false;
			}
		}