Hey Guys
I need some help with an app im writing. Its system tray app that monitors a service. when the user starts the service it should send a notification to all users who have the app opened, that person x is starting the service(a notification bubble should appear). All users on the same network
The app needs to be a client and server app. Server part starts up when the app opens. when a user starts the service, the client part kicks in,sends the message.
There is a db with usernames,machinenames etc.
Can someone please assist. Im not familar with TCP Client and Server stuff.
UPDATE:
ok so this is what i got so far, but im getting an error after a successfull message send
Only one usage of each socket address (protocol/network address/port) is normally permitted at System.Net.Sockets.Socket.DoBind(EndPoint endPointSnapshot, SocketAddress socketAddress)
public void Server()
{
//try
//{
//IPAddress[] addresslist = Dns.GetHostAddresses(Environment.MachineName);
//foreach (IPAddress theaddress in addresslist)
//{
// myIP = (theaddress.ToString());
// MessageBox.Show(myIP);
//}
//this needs to be your ipadress
IPAddress ipAd = IPAddress.Parse(""); //use local m/c IP address, and use the same in the client
TcpListener myList = new TcpListener(ipAd, 8001);
myList.Start();
// MessageBox.Show("The server is running at port 8001...");
//MessageBox.Show("The local End point is :" + myList.LocalEndpoint);
//MessageBox.Show("Waiting for a connection.....");
Socket s = myList.AcceptSocket();
//MessageBox.Show("Connection accepted from " + s.RemoteEndPoint);
byte[] b = new byte[100];
int k = s.Receive(b);
//MessageBox.Show("Recieved...");
char ms;
string ms2 = "";
for (int i = 0; i < k; i++)
{
ms = (Convert.ToChar(b[i]));
ms2 = ms2 + ms;
}
//if (ms2.Substring(0, 5) == "notify")
//{
// ms2 = ms2.Substring(0, 6);
//}
Form1 fmg = new Form1();
fmg.notifyIcon1.ShowBalloonTip(5000, "Attention", ms2, ToolTipIcon.Info);
//MessageBox.Show(ms2); //the message that the client sent back
ASCIIEncoding asen = new ASCIIEncoding();
//s.Send(asen.GetBytes("The string was recieved by the server.")); //sending a acknowledgement message to the client
// MessageBox.Show("\\nSent Acknowledgement");
s.Close();
myList.Stop();
// }
//catch (Exception e)
//{
// MessageBox.Show("Error..... " + e.StackTrace);
}
// }
public void Client(String notifymessage)
{
try
{
TcpClient tcpclnt = new TcpClient();
//MessageBox.Show("Connecting.....");
//the ipadress you want to send the message to
//needs to be stored in a db, loop to send to all users
tcpclnt.Connect("", 8001); // use the ipaddress as in the server program
// MessageBox.Show("Connected");
//MessageBox.Show("Enter the string to be transmitted : ");
// String str = Console.ReadLine();
String str = notifymessage;
Stream stm = tcpclnt.GetStream();
ASCIIEncoding asen = new ASCIIEncoding();
byte[] ba = asen.GetBytes(str);
//MessageBox.Show("Transmitting.....");
stm.Write(ba, 0, ba.Length);
byte[] bb = new byte[100];
int k = stm.Read(bb, 0, 100);
char ms;
string ms2 = "";
for (int i = 0; i < k; i++)
{
ms = (Convert.ToChar(bb[i]));
ms2 = ms2 + ms;
}
//MessageBox.Show(ms2);
tcpclnt.Close();
}
catch (Exception e)
{
MessageBox.Show("Error..... " + e.StackTrace);
}
}
Thanks
Lee