Send() public method

public Send ( Element e ) : void
e Element
return void
 public void XmppSendTest()
 {
     var xmpp = new XmppClientConnection(domain);
     xmpp.ConnectServer = connectserver;
     xmpp.Open(username, password);
     xmpp.OnError += new ErrorHandler(delegate { logerror(); });
     xmpp.OnLogin += delegate(object o) { xmpp.Send(new Message(new Jid(recipient), MessageType.chat, "james")); };
     while (!xmpp.Authenticated)
         System.Threading.Thread.Sleep(500);
     System.Threading.Thread.Sleep(1000);
     xmpp.Send(new Message(new Jid(recipient), MessageType.chat, "james"));
     xmpp.Close();
 }
Example #2
0
 /// <summary>
 /// 命令发送
 /// </summary>
 /// <param name="ToServerName"></param>
 /// <param name="strCommand"></param>
 public void SendCommand(string ToServerName, string strCommand)
 {
     agsXMPP.Jid jid = new agsXMPP.Jid(ToServerName);
     agsXMPP.protocol.client.Message sendMsg = new agsXMPP.protocol.client.Message(jid, MessageType.chat, strCommand);
     objXmpp.Send(sendMsg);
     LogTrace(ToServerName + " " + strCommand);
 }
Example #3
0
        public override void Init(XmppClientConnection con)
        {
            m_XmppClient = con;

            // <auth mechanism="PLAIN" xmlns="urn:ietf:params:xml:ns:xmpp-sasl">$Message</auth>
            m_XmppClient.Send(new protocol.sasl.Auth(protocol.sasl.MechanismType.PLAIN, Message()));
        }
Example #4
0
        /// <summary>
        /// 自动发送消息
        /// </summary>
        private void AutoSendMessage()
        {
            string strContent;
            string strDebug;

            while (true)
            {
                strDebug   = lib.ReadINI("ClientConfig", "Debug");
                strContent = SIC.ShowInfo();
                agsXMPP.Jid jid = new agsXMPP.Jid(this.strMonitorServer);
                agsXMPP.protocol.client.Message autoReply = new agsXMPP.protocol.client.Message(jid, MessageType.chat, strContent);
                if (strDebug == "1")
                {
                    lib.LogTrace(strContent);
                }
                objXmpp.Send(autoReply);
                Thread.Sleep(5000);
            }
        }
Example #5
0
        public async Task<Session.IInfo> AuthenticateAsync(string connectServer, string authenticationToken)
        {
            XmppClientConnection connection = new XmppClientConnection();

            connection.Server = Guest.Server;
            connection.Username = Guest.User;
            connection.Password = GuestPassword;

            connection.AutoResolveConnectServer = false;
            connection.ForceStartTls = false;
            connection.ConnectServer = connectServer; // values.HarmonyHubAddress;
            connection.AutoAgents = false;
            connection.AutoPresence = false;
            connection.AutoRoster = false;
            connection.OnSaslStart += OnSaslStart;
            connection.OnSaslEnd += OnSaslEnd;
            connection.OnXmppConnectionStateChanged += (s, e) => Instrumentation.Xmpp.ConnectionStateChanged(e);
            connection.OnReadXml += (s, e) => Instrumentation.Xmpp.Receive(e);
            connection.OnWriteXml += (s, e) => Instrumentation.Xmpp.Transmit(e);
            connection.OnError += (s, e) => Instrumentation.Xmpp.Error(e);
            connection.OnSocketError += (s, e) => Instrumentation.Xmpp.SocketError(e);

            Task connected = Observable.FromEvent<agsXMPP.ObjectHandler, Unit>(handler => s => handler(Unit.Default), handler => connection.OnLogin += handler, handler => connection.OnLogin -= handler)
                                       .Timeout(TimeSpan.FromSeconds(30))
                                       .Take(1)
                                       .ToTask();

            connection.Open();

            await connected;

            Task<Session.IInfo> session =
                Observable.FromEvent<agsXMPP.protocol.client.IqHandler, agsXMPP.protocol.client.IQEventArgs>(handler => (s, e) => handler(e), handler => connection.OnIq += handler, handler => connection.OnIq -= handler)
                      .Do(args => Instrumentation.Xmpp.IqReceived(args.IQ.From, args.IQ.To, args.IQ.Id, args.IQ.Error, args.IQ.Type, args.IQ.Value))
                      .Do(args => args.Handled = true)
                      .Select(args => args.IQ)
                      .SessionResponses()
                      .Timeout(TimeSpan.FromSeconds(10))
                      .Take(1)
                      .ToTask();

            connection.Send(Builder.ConstructSessionInfoRequest(authenticationToken));

            Session.IInfo sessionInfo = await session;

            connection.Close();

            return sessionInfo;
        }
Example #6
0
        void objXmpp_OnIq(object sender, IQ iq)
        {
            if (iq != null)
            {
                // No Iq with query
                if (iq.HasTag(typeof(agsXMPP.protocol.extensions.si.SI)))
                {
                    if (iq.Type == IqType.set)
                    {
                        agsXMPP.protocol.extensions.si.SI si = iq.SelectSingleElement(typeof(agsXMPP.protocol.extensions.si.SI)) as agsXMPP.protocol.extensions.si.SI;

                        agsXMPP.protocol.extensions.filetransfer.File file = si.File;
                        if (file != null)
                        {
                            // somebody wants to send a file to us
                            //frmFileTransfer frmFile = new frmFileTransfer(XmppCon, iq);
                            //frmFile.Show();
                            Console.WriteLine(file.Description);
                            FileTransfer FT = new FileTransfer(objXmpp, iq);
                        }
                    }
                }
                else
                {
                    Element query = iq.Query;

                    if (query != null)
                    {
                        if (query.GetType() == typeof(agsXMPP.protocol.iq.version.Version))
                        {
                            // its a version IQ VersionIQ
                            agsXMPP.protocol.iq.version.Version version = query as agsXMPP.protocol.iq.version.Version;
                            if (iq.Type == IqType.get)
                            {
                                // Somebody wants to know our client version, so send it back
                                iq.SwitchDirection();
                                iq.Type = IqType.result;

                                version.Name = "MiniClient";
                                version.Ver  = "0.5";
                                version.Os   = Environment.OSVersion.ToString();

                                objXmpp.Send(iq);
                            }
                        }
                    }
                }
            }
        }
Example #7
0
 public Task<ContactDetails> Send()
 {
     var dispatcher = Dispatcher.CurrentDispatcher;
     var connection = ConnectionManager.GetOrCreateConnection(_client);
     _onIq = dispatcher.Wrap<object, IQ>(OnIq);
     _connection = connection.Connection;
     _connection.OnIq += _onIq.Exec;
     var iq = new VcardIq();
     iq.Type = IqType.get;
     iq.To = _jid;
     iq.From = _connection.MyJID;
     iq.Id = _id = Guid.NewGuid().ToString("N");
     _connection.Send(iq);
     return _task.Task;
 }
Example #8
0
        static void Main(string[] args)
        {           
            const string JID_SENDER     = "*****@*****.**";
            const string PASSWORD       = "******";   // password of the JIS_SENDER account

            const string JID_RECEIVER   = "*****@*****.**";

            Jid jidSender = new Jid(JID_SENDER);
            XmppClientConnection xmpp = new  XmppClientConnection(jidSender.Server);
            xmpp.Open(jidSender.User, PASSWORD);            
            xmpp.OnLogin += delegate(object o) { xmpp.Send(new Message(new Jid(JID_RECEIVER), MessageType.chat, "Hello, how are you?")); };

            Console.WriteLine("Wait until you get the message and press a key to continue");
            Console.ReadLine();
            
            xmpp.Close();
        }
        /// <summary>
        /// Attempts to send a gTalk IM to the specified account.
        /// </summary>
        public void GTalk(string username, string password, string sendToUser, string message, int connectionTimeout)
        {
            try
            {
                if (connectionTimeout > GTALK_MAX_CONNECTION_TIMEOUT)
                {
                    connectionTimeout = GTALK_MAX_CONNECTION_TIMEOUT;
                }
                else if (connectionTimeout < GTALK_DEFAULT_CONNECTION_TIMEOUT)
                {
                    connectionTimeout = GTALK_DEFAULT_CONNECTION_TIMEOUT;
                }

                XmppClientConnection xmppCon = null;

                if (m_gtalkConnections.ContainsKey(username))
                {
                    xmppCon = m_gtalkConnections[username];
                    Log("Using existing gTalk connection for " + username + "@gmail.com.");
                    xmppCon.Send(new Message(new Jid(sendToUser + "@gmail.com"), MessageType.chat, message));
                }
                else
                {
                    xmppCon = new XmppClientConnection();
                    xmppCon.Password = password;
                    xmppCon.Username = username;
                    xmppCon.Server = "gmail.com";
                    xmppCon.ConnectServer = "talk.google.com";
                    xmppCon.AutoAgents = false;
                    xmppCon.AutoPresence = false;
                    xmppCon.AutoRoster = false;
                    xmppCon.AutoResolveConnectServer = true;

                    Log("Attempting to connect to gTalk for " + username + ".");

                    ManualResetEvent waitForConnect = new ManualResetEvent(false);

                    xmppCon.OnLogin += new ObjectHandler((sender) => waitForConnect.Set());
                    xmppCon.Open();

                    if (waitForConnect.WaitOne(connectionTimeout, false))
                    {
                        Log("Connected to gTalk for " + username + "@gmail.com.");
                        if (!m_gtalkConnections.ContainsKey(username))
                        {
                            m_gtalkConnections.Add(username, xmppCon);
                        }
                        xmppCon.Send(new Message(new Jid(sendToUser + "@gmail.com"), MessageType.chat, message));
                    }
                    else
                    {
                        Log("Connection to gTalk for " + username + " timed out.");
                    }
                }
                //xmppCon.Close();
            }
            catch (Exception excp)
            {
                logger.Error("Exception GTalk. " + excp.Message);
                Log("Exception GTalk. " + excp.Message);
            }
        }
Example #10
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="con"></param>
 public override void Init(XmppClientConnection con)
 {
     con.Send(new Auth(MechanismType.ANONYMOUS));
 }
Example #11
0
        static void Main(string[] args)
        {
            XmppClientConnection xmppCon = new XmppClientConnection();

            Console.Title = "Console Client";

            // read the jid from the console
            PrintHelp("Enter you Jid ([email protected]): ");
            Jid jid = new Jid(Console.ReadLine());

            PrintHelp(String.Format("Enter password for '{0}': ", jid.ToString()));

            xmppCon.Password = Console.ReadLine();
            xmppCon.Username = jid.User;
            xmppCon.Server = jid.Server;
            xmppCon.AutoAgents = false;
            xmppCon.AutoPresence = true;
            xmppCon.AutoRoster = true;
            xmppCon.AutoResolveConnectServer = true;

            // Connect to the server now
            // !!! this is asynchronous !!!
            try
            {
                xmppCon.OnRosterStart += new ObjectHandler(xmppCon_OnRosterStart);
                xmppCon.OnRosterItem += new XmppClientConnection.RosterHandler(xmppCon_OnRosterItem);
                xmppCon.OnRosterEnd += new ObjectHandler(xmppCon_OnRosterEnd);
                xmppCon.OnPresence += new PresenceHandler(xmppCon_OnPresence);
                xmppCon.OnMessage += new MessageHandler(xmppCon_OnMessage);
                xmppCon.OnLogin += new ObjectHandler(xmppCon_OnLogin);

                xmppCon.Open();

            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            Wait("Login to server, please wait");

            PrintCommands();

            bool bQuit = false;

            while (!bQuit)
            {
                string command = Console.ReadLine();
                string[] commands = command.Split(' ');

                switch (commands[0].ToLower())
                {
                    case "help":
                        PrintCommands();
                        break;
                    case "quit":
                        bQuit = true;
                        break;
                    case "msg":
                        string msg = command.Substring(command.IndexOf(commands[2]));
                        xmppCon.Send(new Message(new Jid(commands[1]), MessageType.chat, msg));
                        break;
                    case "status":
                        switch (commands[1])
                        {
                            case "online":
                                xmppCon.Show = ShowType.NONE;
                                break;
                            case "away":
                                xmppCon.Show = ShowType.away;
                                break;
                            case "xa":
                                xmppCon.Show = ShowType.xa;
                                break;
                            case "chat":
                                xmppCon.Show = ShowType.chat;
                                break;
                        }
                        string status = command.Substring(command.IndexOf(commands[2]));
                        xmppCon.Status = status;
                        xmppCon.SendMyPresence();
                        break;
                }
            }

            // close connection
            xmppCon.Close();
        }
Example #12
0
        static void Main(string[] args) {
            Console.Title = "XMPPduino";

            xmppCon = new XmppClientConnection();

            System.ComponentModel.IContainer components = new System.ComponentModel.Container();
            serialPort = new System.IO.Ports.SerialPort(components);

            serialPort.PortName = Config.COM_PORT;
            serialPort.BaudRate = Config.Baud_Rate;

            xmppCon = new XmppClientConnection();
            xmppCon.Username = Config.Username;
            xmppCon.Password = Config.Password;
            xmppCon.SocketConnectionType = agsXMPP.net.SocketConnectionType.Direct;
            xmppCon.ConnectServer = "talk.google.com";
            xmppCon.Port = 5222;
            xmppCon.UseStartTLS = true;
            xmppCon.AutoResolveConnectServer = false;
            xmppCon.Show = ShowType.chat;
            xmppCon.Server = Config.Server;

            xmppCon.AutoAgents = false;
            xmppCon.AutoPresence = true;
            xmppCon.AutoRoster = true;

            try {
                xmppCon.OnRosterStart += new ObjectHandler(xmppCon_OnRosterStart);
                xmppCon.OnRosterItem += new XmppClientConnection.RosterHandler(xmppCon_OnRosterItem);
                xmppCon.OnRosterEnd += new ObjectHandler(xmppCon_OnRosterEnd);
                xmppCon.OnPresence += new PresenceHandler(xmppCon_OnPresence);
                xmppCon.OnMessage += new MessageHandler(xmppCon_OnMessage);
                xmppCon.OnLogin += new ObjectHandler(xmppCon_OnLogin);
                xmppCon.Open();
            }
            catch (Exception e) {
                Console.WriteLine(e.Message);
            }

            Wait("Login to server, please wait");
            bool bQuit = false;

            while (!bQuit) {
                string command = Console.ReadLine();
                string[] commands = command.Split(' ');

                switch (commands[0].ToLower()) {
                    case "quit":
                        bQuit = true;
                        break;
                    case "msg":
                        string msg = command.Substring(command.IndexOf(commands[2]));
                        xmppCon.Send(new Message(new Jid(commands[1]), MessageType.chat, msg));
                        break;
                    case "status":
                        switch (commands[1]) {
                            case "online":
                                xmppCon.Show = ShowType.NONE;
                                break;
                            case "away":
                                xmppCon.Show = ShowType.away;
                                break;
                            case "xa":
                                xmppCon.Show = ShowType.xa;
                                break;
                            case "chat":
                                xmppCon.Show = ShowType.chat;
                                break;
                        }
                        string status = command.Substring(command.IndexOf(commands[2]));
                        xmppCon.Status = status;
                        xmppCon.SendMyPresence();
                        break;
                }
            }
            xmppCon.Close();
        }