Click here to Skip to main content
13,006,180 members (66,699 online)
Rate this:
Please Sign up or sign in to vote.
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.


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()

//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);
// 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);
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");

// }
//catch (Exception e)
// MessageBox.Show("Error..... " + e.StackTrace);
// }

public void Client(String notifymessage)
TcpClient tcpclnt = new TcpClient();
//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);
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;


catch (Exception e)
MessageBox.Show("Error..... " + e.StackTrace);


Posted 2-Feb-11 6:58am
Updated 3-Feb-11 6:48am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

You could look at using WCF to abstract some of the low level socket and TCP coding away. This way it is just in a configuration and you can forcus more on the app itself.

Sasha did a good article on using WCF for a chat app. It might help you to see what WCF can do for you.

WCF / WPF Chat Application[^]

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170628.1 | Last Updated 3 Feb 2011
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100