Click here to Skip to main content
12,304,823 members (67,816 online)
Click here to Skip to main content
Articles » Languages » C# » General » Downloads

Stats

59.9K views
2.4K downloads
72 bookmarked
Posted

Notification Client and Server Written in C#

, 22 Oct 2007 CPOL
Notification Client and Server written in C#
NotifyClient.exe
NotifyServer.exe
info.ico
/*
 * Created by SharpDevelop.
 * User: sollw2
 * Date: 10/18/2007
 * Time: 1:54 PM
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */
using System;
using System.Net.Sockets;
using System.Text;

namespace NotifyClient
{
	class Program
	{
		public static void Main(string[] args)
		{
			
			// TODO: Implement Functionality Here
			if (args.Length != 6)
			{
				Console.Write("Usage: NotifyClient.exe host port timeout[milliseconds] icon[INFO|WARN|ERROR|NONE] title message\n\n");
				System.Environment.Exit(1);
			}
			StringBuilder myMessage = new System.Text.StringBuilder();
			myMessage.AppendFormat("{0}|{1}|{2}|{3}",args[2],args[3],args[4],args[5]);
			try
			{
				TcpClient client = new TcpClient();
				ASCIIEncoding encoder = new ASCIIEncoding();
				byte[] buffer = encoder.GetBytes(myMessage.ToString());
				client.Connect(args[0], Convert.ToInt16(args[1]));
				NetworkStream stream = client.GetStream();
				stream.Write(buffer, 0, buffer.Length);
				stream.Close();
				client.Close();
				Console.WriteLine("Message was sent to host " + args[0] + " on port " + args[1]);
			}
			catch(System.Exception e)
			{
				Console.WriteLine("Message was not sent");
			}
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

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

Share

About the Author

Helbrax
Web Developer
United States United States
No Biography provided

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.160530.1 | Last Updated 22 Oct 2007
Article Copyright 2007 by Helbrax
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid