Exemplo n.º 1
0
        public override void  connect()
        {
            /*
             * Connects to mod_eventsocket, authenticates and sets event filter.
             * Returns True on success or raises ConnectError exception on failure.
             */
            base.connect();
            Event filter_response;

            //# Connects transport, if connection fails, raise ConnectError
            try
            {
                transport.connect();
            }
            catch (Exception ex)
            {
                throw new ConnectError("Cannot to the server");
            }
            start_event_handler();

            //Send password to the socket
            Event evnt = auth(password);

            if (!evnt.IsReplyTextSuccess() && evnt == null)
            {
                throw new ConnectError("Authentication Failed...");
            }

            // Sets event filter or raises ConnectError
            if (!string.IsNullOrEmpty(_filter))
            {
                if (_is_eventjson)
                {
                    filter_response = EventJson(_filter);
                }
                else
                {
                    filter_response = EventPlain(_filter);
                }
                if (!filter_response.IsReplyTextSuccess())
                {
                    disconnect();
                    throw new ConnectError("Event filter failure");
                }
            }

            // Sets connected flag to True
            connected = true;
        }