protected ASocket(Socket socket)
 {
     _textReceived           = "";
     _processingMessages     = new List <string>();
     _splitMessages          = new List <string>();
     _awaitingCommandsEvents = new Queue <ManualResetEvent>();
     _awaitingCommandReturns = new Dictionary <string, string>();
     _commandThreads         = new Dictionary <string, ManualResetEvent>();
     _awaitingCommandReturns = new Dictionary <string, string>();
     _eventProcessor         = new delProcessEventMessage(ProcessEvent);
     _handlers    = new List <sEventHandler>();
     _socket      = socket;
     _isConnected = _socket.Connected;
     if (!_isConnected)
     {
         throw new Exception("Unable to construct an instance of the abstract class ASocket using the contructor with a socket without passing a connected socket.");
     }
     _ipAddress = ((IPEndPoint)_socket.RemoteEndPoint).Address;
     _port      = ((IPEndPoint)_socket.RemoteEndPoint).Port;
     _preSocketReady();
     _mreMessageWaiting   = new ManualResetEvent(false);
     _backgroundProcessor = new Thread(new ThreadStart(_MessageProcessorStart));
     _backgroundProcessor.IsBackground = true;
     _backgroundProcessor.Start();
     _socket.ReceiveTimeout             = 1000;
     _backgroundDataReader              = new Thread(new ThreadStart(_SocketDataReaderStart));
     _backgroundDataReader.IsBackground = true;
     _backgroundDataReader.Start();
     this.RegisterEvent(BACKGROUND_API_RESPONSE_EVENT);
 }
        protected ASocket(IPAddress ip, int port)
        {
            _textReceived           = "";
            _processingMessages     = new List <string>();
            _splitMessages          = new List <string>();
            _awaitingCommandsEvents = new Queue <ManualResetEvent>();
            _awaitingCommandReturns = new Dictionary <string, string>();
            _commandThreads         = new Dictionary <string, ManualResetEvent>();
            _awaitingCommandReturns = new Dictionary <string, string>();
            _eventProcessor         = new delProcessEventMessage(ProcessEvent);
            _handlers            = new List <sEventHandler>();
            _exit                = false;
            _isConnected         = false;
            _ipAddress           = ip;
            _port                = port;
            _awaitingCommands    = new Queue <byte[]>();
            _socket              = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            _mreMessageWaiting   = new ManualResetEvent(false);
            _backgroundProcessor = new Thread(new ThreadStart(_MessageProcessorStart));
            _backgroundProcessor.Start();
            _socket.ReceiveTimeout = 1000;
            _preSocketReady();
            Thread th = new Thread(new ThreadStart(BackgroundRun));

            th.IsBackground = true;
            th.Start();
        }
 protected ASocket(Socket socket)
 {
     _textReceived = "";
     _processingMessages = new List<string>();
     _splitMessages = new List<string>();
     _awaitingCommandsEvents = new Queue<ManualResetEvent>();
     _awaitingCommandReturns = new Dictionary<string, string>();
     _commandThreads = new Dictionary<string, ManualResetEvent>();
     _awaitingCommandReturns = new Dictionary<string, string>();
     _eventProcessor = new delProcessEventMessage(ProcessEvent);
     _handlers = new List<sEventHandler>();
     _socket = socket;
     _isConnected = _socket.Connected;
     if (!_isConnected)
         throw new Exception("Unable to construct an instance of the abstract class ASocket using the contructor with a socket without passing a connected socket.");
     _ipAddress = ((IPEndPoint)_socket.RemoteEndPoint).Address;
     _port = ((IPEndPoint)_socket.RemoteEndPoint).Port;
     _preSocketReady();
     _mreMessageWaiting = new ManualResetEvent(false);
     _backgroundProcessor = new Thread(new ThreadStart(_MessageProcessorStart));
     _backgroundProcessor.IsBackground = true;
     _backgroundProcessor.Start();
     _socket.ReceiveTimeout = 1000;
     _backgroundDataReader = new Thread(new ThreadStart(_SocketDataReaderStart));
     _backgroundDataReader.IsBackground = true;
     _backgroundDataReader.Start();
     this.RegisterEvent(BACKGROUND_API_RESPONSE_EVENT);
 }
 public OutboundSocket(IPAddress ip, int port, string password, delProcessEventMessage eventDelegate, delProcessLogMessage logDelegate, delReloadXml preReloadCall, delReloadXml postReloadCall)
     : base(ip, port)
 {
     _eventDelegate  = eventDelegate;
     _logDelegate    = logDelegate;
     _preReloadCall  = preReloadCall;
     _postReloadCall = postReloadCall;
     _password       = password;
 }
 public sEventHandler(string eventName, string uuid, string callerUUID, string channelName, delProcessEventMessage handler, long id)
 {
     _eventName   = eventName;
     _uuid        = uuid;
     _callerUUID  = callerUUID;
     _channelName = channelName;
     _handler     = handler;
     _id          = id;
 }
 public OutboundSocket(IPAddress ip,int port,string password,delProcessEventMessage eventDelegate,delProcessLogMessage logDelegate,delReloadXml preReloadCall,delReloadXml postReloadCall)
     : base(ip,port)
 {
     _eventDelegate = eventDelegate;
     _logDelegate = logDelegate;
     _preReloadCall = preReloadCall;
     _postReloadCall = postReloadCall;
     _password = password;
 }
        public long RegisterEventHandler(string eventName, string uuid, string callerUUID, string channelName, delProcessEventMessage handler)
        {
            long id = _random.NextLong();

            lock (_handlers)
            {
                _handlers.Add(new sEventHandler(eventName, uuid, callerUUID, channelName, handler, id));
            }
            return(id);
        }
 protected ASocket(IPAddress ip, int port)
 {
     _textReceived = "";
     _processingMessages = new List<string>();
     _splitMessages = new List<string>();
     _awaitingCommandsEvents = new Queue<ManualResetEvent>();
     _awaitingCommandReturns = new Dictionary<string, string>();
     _commandThreads = new Dictionary<string, ManualResetEvent>();
     _awaitingCommandReturns = new Dictionary<string, string>();
     _eventProcessor = new delProcessEventMessage(ProcessEvent);
     _handlers = new List<sEventHandler>();
     _exit = false;
     _isConnected = false;
     _ipAddress = ip;
     _port = port;
     _awaitingCommands = new Queue<byte[]>();
     _socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
     _mreMessageWaiting = new ManualResetEvent(false);
     _backgroundProcessor = new Thread(new ThreadStart(_MessageProcessorStart));
     _backgroundProcessor.Start();
     _socket.ReceiveTimeout = 1000;
     _preSocketReady();
     Thread th = new Thread(new ThreadStart(BackgroundRun));
     th.IsBackground = true;
     th.Start();
 }
 public sEventHandler(string eventName, string uuid,string callerUUID,string channelName, delProcessEventMessage handler,long id)
 {
     _eventName = eventName;
     _uuid = uuid;
     _callerUUID = callerUUID;
     _channelName = channelName;
     _handler = handler;
     _id = id;
 }
 public long RegisterEventHandler(string eventName, string uuid, string callerUUID, string channelName, delProcessEventMessage handler)
 {
     long id = _random.NextLong();
     lock (_handlers)
     {
         _handlers.Add(new sEventHandler(eventName, uuid, callerUUID, channelName, handler, id));
     }
     return id;
 }