Ejemplo n.º 1
0
Archivo: Main.cs Proyecto: bwail/xmpp
 public Main()
 {
     InitializeComponent();
     //CompressionRegistry.Instance.AddCompression(Assembly.LoadFile(Application.StartupPath + @"\ubiety.compression.sharpziplib.dll"));
     Errors.Instance.OnError += Errors_OnError;
     _xmpp = new XMPP();
     slVersion.Text = Resources.Version_Label + XMPP.Version;
 }
Ejemplo n.º 2
0
 private void button1_Click(object sender, EventArgs e)
 {
     XID id = new XID(txtUsername.Text);
     xmpp = XMPP.Connect(id, txtPassword.Text, ssl: btnSSL.Checked);
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Connect to an XMPP server.
        /// </summary>
        /// <param name="id">The XID to be used for connecting.</param>
        /// <param name="password">The password to be used for authentication</param>
        /// <param name="hostname">The hostname to connect to. Can be set to null to use XID server.</param>
        /// <param name="port">The port to connect to if one is not provided by an SRV record.</param>
        /// <param name="ssl">Use encryption if available?</param>
        /// <returns></returns>
        public static XMPP Connect(XID id, string password, string hostname = null, int port = 5222, bool ssl = false)
        {
            XMPP me = new XMPP();

            _states.Socket = new AsyncSocket();
            // We need an XID and Password to connect to the server.
            if (String.IsNullOrEmpty(password))
            {
                _errors.SendError(typeof(XMPP), ErrorType.MissingPassword, "Set the Password property before connecting.", true);
                return null;
            }
            else if (String.IsNullOrEmpty(id))
            {
                _errors.SendError(typeof(XMPP), ErrorType.MissingID, "Set the ID property before connecting.", true);
                return null;
            }

            // Do we use the server supplied from the XID or the alternate provided by the developer?
            if (!String.IsNullOrEmpty(hostname))
                _states.Socket.Hostname = hostname;
            else
                _states.Socket.Hostname = id.Server;

            Logger.InfoFormat(typeof(XMPP), "Connecting to {0}", _states.Socket.Hostname);

            _states.ID = id;
            _states.Password = password;

            // Set the values we need to connect.
            _states.Socket.SSL = ssl;
            _states.Socket.Port = port;
            // Set the current state to connecting and start the process.
            _states.State = new ConnectingState();
            _states.Execute();

            return me;
        }