예제 #1
0
		/// <summary> Closes the socket connection.</summary>
		private void disconnect(bool withDie)
		{
			lock (lockSocket)
			{
				if (withDie)
				{
					reconnectEnable = false;
					reconnected = false;
					enableEvents = true;
				}

				if (mrReader != null)
				{
					if (withDie)
					{
						mrReader.Die = true;
						mrReader = null;
					}
					else
						mrReader.Socket = null;
				}

				if (this.mrSocket != null)
				{
					mrSocket.Close();
					mrSocket = null;
				}

				responseEventHandlers.Clear();
				responseHandlers.Clear();
				pingHandlers.Clear();
			}
		}
예제 #2
0
		protected internal bool connect()
		{
			bool result = false;
			bool startReader = false;

			lock (lockSocket)
			{
				if (mrSocket == null)
				{
#if LOGGER
					logger.Info("Connecting to {0}:{1}", hostname, port);
#endif
					try
					{
						mrSocket = new SocketConnection(hostname, port, socketEncoding);
						result = mrSocket.IsConnected;
					}
#if LOGGER
					catch (Exception ex)
					{
						logger.Info("Connect - Exception  : {0}", ex.Message);
#else
					catch
					{
#endif
						result = false;
					}
                    if (result)
                    {
                        if (mrReader == null)
                        {
                            mrReader = new ManagerReader(this);
                            mrReaderThread = new Thread(mrReader.Run) { IsBackground = true, Name = "ManagerReader-" + DateTime.Now.Second };
                            mrReader.Socket = mrSocket;
                            startReader = true;
                        }
                        else
                        {
                            mrReader.Socket = mrSocket;
                        }

                        mrReader.Reinitialize();
                    }
                    else
                    {
                        mrSocket = null;
                    }
				}
			}

            if (startReader)
            {
                mrReaderThread.Start();
            }

			return IsConnected();
		}