| | |
I try to create a Windows Service which listens to UDP port 514, i install it using i
Please support our C# advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: May 2007
Posts: 5
Reputation:
Solved Threads: 0
I try to create a Windows Service which listens to UDP port 514, i install it using i
0
#1 Oct 10th, 2008
I try to create a Windows Service which listens to UDP port 514, i install it using installutil.exe and i get the following error message:
---------------------------
Services
---------------------------
The SyslogService2005 service on Local Computer started and then stopped. Some services stop automatically if they are not in use by other services or programs.
---------------------------
OK
---------------------------
In practise it starts working till the progressbar in Properties Window ends!
my code:
---------------------------
Services
---------------------------
The SyslogService2005 service on Local Computer started and then stopped. Some services stop automatically if they are not in use by other services or programs.
---------------------------
OK
---------------------------
In practise it starts working till the progressbar in Properties Window ends!
my code:
c# Syntax (Toggle Plain Text)
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Diagnostics; //using System.Linq; using System.ServiceProcess; using System.Text; using System.Net.Sockets; using System.Net; using MySql.Data; using MySql.Data.MySqlClient; using System.Threading; using System.IO; namespace SyslogService2005 { public partial class Service1 : ServiceBase { public Service1() { InitializeComponent(); this.ServiceName = "SyslogServiceUDP514"; this.CanStop = true; this.CanPauseAndContinue = true; this.AutoLog = true; } private const int listenPort = 514; class UdpState { public UdpClient u; public IPEndPoint e; } public static bool messageReceived = false; public static bool processWorking = false; public static void ReceiveCallback(IAsyncResult ar) { UdpClient u = (UdpClient)((UdpState)(ar.AsyncState)).u; IPEndPoint e = (IPEndPoint)((UdpState)(ar.AsyncState)).e; Byte[] receiveBytes = u.EndReceive(ar, ref e); string receiveString = Encoding.ASCII.GetString(receiveBytes); LogMessageToFile(receiveString); //Console.WriteLine("Received: {0}", receiveString); messageReceived = true; } private static void StartListener() { // Receive a message and write it to the console. //LogMessageToFile("ReceiveMessage"); IPEndPoint e = new IPEndPoint(IPAddress.Any, listenPort); //LogMessageToFile("UdpClient"); UdpClient u = new UdpClient(e); //LogMessageToFile("UdpState"); UdpState s = new UdpState(); //LogMessageToFile("s.e = e"); s.e = e; // LogMessageToFile("s.u"); s.u = u; //Console.WriteLine("listening for messages"); //LogMessageToFile("Start Asychronous"); while (processWorking==true) { u.BeginReceive(new AsyncCallback(ReceiveCallback), s); // Do some work while we wait for a message. For this example, // we'll just sleep while (!messageReceived) { //LogMessageToFile("Sleep 100 ms"); Thread.Sleep(100); } } } static void LogMessageToFile(string msg) { System.IO.StreamWriter sw = System.IO.File.AppendText("C:\\Services\\LogFile.txt"); try { string logLine = System.String.Format("{0:G}: {1}.", System.DateTime.Now, msg); sw.WriteLine("+----------------------------------------------------------------+"); sw.WriteLine(logLine); } finally { sw.Close(); } } protected override void OnStart(string[] args) { // TODO: Add code here to start your service. //LogMessageToFile("Service Started"); processWorking = true; //StartListener(); //ThreadStart job = new ThreadStart(StartListener); //Thread thread = new Thread(job); //thread.Start(); //LogMessageToFile("StartListener Started"); StartListener(); } protected override void OnStop() { // TODO: Add code here to perform any tear-down necessary to stop your service. if ((Thread.CurrentThread != null) && (Thread.CurrentThread.IsAlive)) { processWorking = false; Thread.Sleep(5000); Thread.CurrentThread.Abort(); LogMessageToFile("Service Stopped"); } } } }
•
•
Join Date: Aug 2008
Posts: 1,735
Reputation:
Solved Threads: 186
Re: I try to create a Windows Service which listens to UDP port 514, i install it using i
0
#2 Oct 10th, 2008
•
•
Join Date: May 2007
Posts: 5
Reputation:
Solved Threads: 0
Re: I try to create a Windows Service which listens to UDP port 514, i install it using i
0
#3 Oct 12th, 2008
•
•
Join Date: Aug 2008
Posts: 1,735
Reputation:
Solved Threads: 186
Re: I try to create a Windows Service which listens to UDP port 514, i install it using i
0
#4 Oct 12th, 2008
•
•
Join Date: May 2007
Posts: 5
Reputation:
Solved Threads: 0
Re: I try to create a Windows Service which listens to UDP port 514, i install it using i
0
#5 Oct 12th, 2008
•
•
Join Date: Aug 2008
Posts: 1,735
Reputation:
Solved Threads: 186
Re: I try to create a Windows Service which listens to UDP port 514, i install it using i
0
#6 Oct 12th, 2008
Depending on which OS and wether you're part of a domain etc, windows 2003 for example is common to have it so you cannot interact with the desktop.. if it thinks for any reaosn you might, the service doesnt work.
Did I just hear "You gotta help us, Doc. We've tried nothin' and we're all out of ideas" ? Is this you? Dont let this be you! I will put in as much effort as you seem to.
•
•
Join Date: May 2007
Posts: 5
Reputation:
Solved Threads: 0
Re: I try to create a Windows Service which listens to UDP port 514, i install it using i
0
#7 Oct 13th, 2008
•
•
Join Date: Aug 2008
Posts: 1,735
Reputation:
Solved Threads: 186
Re: I try to create a Windows Service which listens to UDP port 514, i install it using i
0
#8 Oct 13th, 2008
![]() |
Other Threads in the C# Forum
- Previous Thread: Socket programming in C#
- Next Thread: How do you draw a bar
| Thread Tools | Search this Thread |
.net access activedirectory ado.net algorithm array barchart basic bitmap box broadcast buttons c# check checkbox client combobox contorl control conversion csharp custom database datagrid datagridview dataset datetime degrees deployment development disabled displayingopenforms draganddrop drawing editing editor encryption enum event excel file form format forms function gdi+ httpwebrequest i18n image imageprocessing index input install java label list listbox mandelbrot math mathematics mouseclick mysql operator oracle path photoshop picturebox pixelinversion post prime programming radians regex remote remoting richtextbox rows server sleep socket sql statistics stream string table text textbox thread time timer update user usercontrol validation visualstudio webbrowser windows winforms wpf xml






