Web Services c#, Sending notifications Clients
- by Diode
I want to send a notification (say a string) to subscribers(subscribers ip addresses are in a database on the server side) by calling another method. when ever I call that method the output becomes error-some.
[WebMethod]
public string GetGroupPath(string emailAddress, string password, string ipAddress)
{
//SqlDataAdapter dbadapter = null;
DataSet returnDS = new DataSet();
string groupName = null;
string groupPath = null;
SqlConnection dbconn = new SqlConnection("Server = localhost;Database=server;User ID = admin;Password = password;Trusted_Connection=false;");
dbconn.Open();
SqlCommand cmd = new SqlCommand();
string getGroupName = "select users.groupname from users where emailaddress = "+"'"+ emailAddress+"'"+ " and "+ "users.password = " + "'" +password+"'";
cmd.CommandText = getGroupName;
cmd.Connection = dbconn;
SqlDataReader reader = null;
try
{
reader = cmd.ExecuteReader();
while (reader.Read())
{
groupName = reader["groupname"].ToString();
}
}
catch (Exception)
{
groupPath = "Invalied";
}
dbconn.Close();
dbconn.Open();
if (groupName != null)
{
string getPath = "select groups.grouppath from groups where groupname = " + "'" + groupName + "'";
cmd.CommandText = getPath;
cmd.Connection = dbconn;
try
{
reader = cmd.ExecuteReader();
while (reader.Read())
{
groupPath = reader["grouppath"].ToString();
}
}
catch
{
groupPath = "Invalied";
}
}
else
groupPath = "Invalied";
dbconn.Close();
if (groupPath != "Invalied")
{
dbconn.Open();
string getPath = "update users set users.ipaddress = "+"'"+ipAddress+"'"+" where users.emailaddress = " + "'" + emailAddress + "'";
cmd.CommandText = getPath;
cmd.Connection = dbconn;
cmd.ExecuteNonQuery();
dbconn.Close();
}
NotifyUsers();
//NotifyUsers nu = new NotifyUsers();
//List<string> ipList = new List<string>();
//ipList.Add("192.168.56.1");
//nu.Notify();
return groupPath;
}
private void NotifyUsers()
{
Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
byte[] ipb = Encoding.ASCII.GetBytes("255.255.255.255");
IPAddress ipAddress = new IPAddress(ipb);
IPEndPoint endPoint = new IPEndPoint(ipAddress, 15000);
string notification = "new_update";
byte[] sendBuffer = Encoding.ASCII.GetBytes(notification);
sock.SendTo(sendBuffer, endPoint);
sock.Close();
}
This is what has to be basically done. in the server side I have a listening thread and it gets notification when the server sends data( assume for now the database contains client ip address). then ever I call the web method it gives a error "invalid IPAddress" atline
byte[] ipb = Encoding.ASCII.GetBytes("255.255.255.255");
thank you :) since this is my first ever post please be kind enough to give me a better feedback too :)
thaks