Subject: OnMessage function is cyclized
Hello to you all!, My problem is this, I coded a simple client in C# for sending group messages (at different customer accounts that have on their lists, it is not a chat room), the problem I have is when the client program receives the messages that are cycled and this does not send the message. This is the code I'm using the function onMessage
My problem is that the function is cycled and shows no error message.
This is main function:
public static agsXMPP.XmppClientConnection cliente = new agsXMPP.XmppClientConnection();
public static Jid user = new Jid("test@domain.org");
public static Jid pass = new Jid("test");
static void Main(string[] args)
{
try
{
con.ConnectionString = "Server= 127.0.0.1;Port=5432;User Id=*;Password=*;Database=*;";
try
{
con.Open();
}
catch (NpgsqlException npg_exception)
{
con.Close();
Console.WriteLine(npg_exception.Message);
throw new Exception(npg_exception.Message);
}
finally
{
Console.WriteLine("DB connection ok...");
Console.WriteLine();
Console.WriteLine();
}
}
catch (NpgsqlException npg_exception)
{
con.Close();
Console.WriteLine(npg_exception.Message);
throw new Exception(npg_exception.Message);
}
Console.WriteLine("Try to connect server talk.google.com..");
Console.WriteLine();
try
{
cliente.Server = "google.com";
cliente.ConnectServer = "talk.google.com";
cliente.Port = 5222;
cliente.AutoRoster = true;
cliente.AutoPresence = true;
cliente.AutoResolveConnectServer = false;
cliente.OnLogin += new ObjectHandler(cliente_OnLogin);
cliente.OnError += new ErrorHandler(cliente_OnError);
cliente.OnMessage += new agsXMPP.protocol.client.MessageHandler(cliente_OnMessage);
cliente.Open(user, pass, "home");
}
catch (agsXMPP.exceptions.XmlRpcException xml_ex)
{
con.Close();
Console.WriteLine(xml_ex.Message);
throw new Exception(xml_ex.Message);
}
finally
{
Console.ReadKey();
}
}
Any help or ideas is welcome.
**Sorry for my inconsistency in few words was made with the google translator.
static void cliente_OnMessage(object sender, agsXMPP.protocol.client.Message msg)
{
string name="", bot_name="";
int id_usr=0;
NpgsqlCommand findBotName= con.CreateCommand();
string mailsender = msg.From.User +"@"+msg.From.Server;
findBotName.CommandText = "select * from usuario where email='" + mailsender+"'";
NpgsqlDataReader rec = findBotName.ExecuteReader();
while (rec.Read())
{
name = rec.GetString(0);
bot_name = rec.GetString(1);
id_usr = rec.GetInt32(2);
}
findBotName.Dispose();
rec.Dispose();
//get mail list to send message
NpgsqlCommand toSend = con.CreateCommand();
toSend.CommandText = "select mail from usr where trim(mail) like '%domain.org' and trim(mail)!='"+mailsender+"'";
NpgsqlDataReader recept = toSend.ExecuteReader();
//Send messages to users
Console.WriteLine(msg.From.User + "@" + msg.From.Server + " says: " + msg.Body);
while(recept.Read())
{
Console.WriteLine("Send to: {0} message is: {1}", recept.GetString(0), msg.Body);
client.Send(new agsXMPP.protocol.client.Message(recept.GetString(0), MessageType.chat, bot_name + " say: " + msg.Body));
}
toSend.Dispose();
recept.Dispose();
}
{
string name="", bot_name="";
int id_usr=0;
NpgsqlCommand findBotName= con.CreateCommand();
string mailsender = msg.From.User +"@"+msg.From.Server;
findBotName.CommandText = "select * from usuario where email='" + mailsender+"'";
NpgsqlDataReader rec = findBotName.ExecuteReader();
while (rec.Read())
{
name = rec.GetString(0);
bot_name = rec.GetString(1);
id_usr = rec.GetInt32(2);
}
findBotName.Dispose();
rec.Dispose();
//get mail list to send message
NpgsqlCommand toSend = con.CreateCommand();
toSend.CommandText = "select mail from usr where trim(mail) like '%domain.org' and trim(mail)!='"+mailsender+"'";
NpgsqlDataReader recept = toSend.ExecuteReader();
//Send messages to users
Console.WriteLine(msg.From.User + "@" + msg.From.Server + " says: " + msg.Body);
while(recept.Read())
{
Console.WriteLine("Send to: {0} message is: {1}", recept.GetString(0), msg.Body);
client.Send(new agsXMPP.protocol.client.Message(recept.GetString(0), MessageType.chat, bot_name + " say: " + msg.Body));
}
toSend.Dispose();
recept.Dispose();
}
My problem is that the function is cycled and shows no error message.
This is main function:
public static agsXMPP.XmppClientConnection cliente = new agsXMPP.XmppClientConnection();
public static Jid user = new Jid("test@domain.org");
public static Jid pass = new Jid("test");
static void Main(string[] args)
{
try
{
con.ConnectionString = "Server= 127.0.0.1;Port=5432;User Id=*;Password=*;Database=*;";
try
{
con.Open();
}
catch (NpgsqlException npg_exception)
{
con.Close();
Console.WriteLine(npg_exception.Message);
throw new Exception(npg_exception.Message);
}
finally
{
Console.WriteLine("DB connection ok...");
Console.WriteLine();
Console.WriteLine();
}
}
catch (NpgsqlException npg_exception)
{
con.Close();
Console.WriteLine(npg_exception.Message);
throw new Exception(npg_exception.Message);
}
Console.WriteLine("Try to connect server talk.google.com..");
Console.WriteLine();
try
{
cliente.Server = "google.com";
cliente.ConnectServer = "talk.google.com";
cliente.Port = 5222;
cliente.AutoRoster = true;
cliente.AutoPresence = true;
cliente.AutoResolveConnectServer = false;
cliente.OnLogin += new ObjectHandler(cliente_OnLogin);
cliente.OnError += new ErrorHandler(cliente_OnError);
cliente.OnMessage += new agsXMPP.protocol.client.MessageHandler(cliente_OnMessage);
cliente.Open(user, pass, "home");
}
catch (agsXMPP.exceptions.XmlRpcException xml_ex)
{
con.Close();
Console.WriteLine(xml_ex.Message);
throw new Exception(xml_ex.Message);
}
finally
{
Console.ReadKey();
}
}
Any help or ideas is welcome.
**Sorry for my inconsistency in few words was made with the google translator.
The author has attached one file to this post:
pruebaLog.txt 354.3 kBytes
You have no permission to open this file.
You have no permission to open this file.
This post was edited on 2012-05-18, 18:56 by ethush.
Edit reason: Attach XML Log file
Edit reason: Attach XML Log file