[Mono-bugs] [Bug 78683][Wis] New - TcpListener Class not starting with service application

bugzilla-daemon at bugzilla.ximian.com bugzilla-daemon at bugzilla.ximian.com
Wed Jun 21 13:40:43 EDT 2006


Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.

Changed by lee.jenkins at datatrakpos.com.

http://bugzilla.ximian.com/show_bug.cgi?id=78683

--- shadow/78683	2006-06-21 13:40:42.000000000 -0400
+++ shadow/78683.tmp.7107	2006-06-21 13:40:42.000000000 -0400
@@ -0,0 +1,139 @@
+Bug#: 78683
+Product: Mono: Class Libraries
+Version: 1.0
+OS: Red Hat 7.0
+OS Details: Actually CentOS 4x (Not sure which RH it's based on)
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Wishlist
+Component: System
+AssignedTo: mono-bugs at ximian.com                            
+ReportedBy: lee.jenkins at datatrakpos.com               
+QAContact: mono-bugs at ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: TcpListener Class not starting with service application
+
+General:
+When trying to implement the class TcpListener within a sevice 
+application, the calling method that creates and starts the TcpListerer 
+class is never called from the OnStart event of the service class.
+
+Detail: 
+In trying to track down the problem, I implemented a simple logging 
+function that appended a line to a log file.  I then placed this function 
+in various points the in execution path of the application, specifically 
+the OnStart, OnStop events as well as within the StartServe() method 
+detailed below.
+
+So in the OnStart event, I would write a line to the log file such 
+as "OnStart Event Fired: + DateTime.Now.ToString();.
+
+Output was noted only in the OnStart and OnStop events depending on how I 
+created the IPAddress for the TcpListener to use.  Not once does it 
+appear that the StartServe() method is ever called and thus no logging to 
+the log file to indicate it either.
+
+I am using Mono 1.1.15.
+
+The following code produces the problem taken from a service application:
+
+protected override void OnStart(string[] args)
+    {
+      try
+      {
+        this.StartServ();
+      }
+      catch (Exception e)
+      {
+        Console.WriteLine(e.ToString());
+      }
+    }
+
+private void StartServe()
+    {
+      TcpListener SockServer = null;
+      try
+      {
+        // Had placed here a logging function to see
+        // if execution got this far, but it did not so
+        // this method was never even called.
+
+        // Setup socket server
+        Int32 port = 4567;
+        
+        // SETUP IP ADDRESS
+        // If this method is used (below), only the OnStart 
+        // event is logged.
+        // Alternatively, if I createt the TcpListener with
+        // TcpListener(IpAddress.Any, port); both the OnStart and OnStop
+        // events are fired, but still the StartServe() method is never
+        // run.
+        IPAddress addr = IPAddress.Parse("127.0.0.1");
+        SockServer = new TcpListener(addr, port);
+        SockServer.Start();
+
+
+        // create buffer to read data
+        Byte[] bytes = new Byte[256];
+        string data = null;
+
+        while (true)
+        {
+          System.Threading.Thread.Sleep(1500);
+          // check to see if request is pending
+          if (SockServer.Pending())
+          {
+            TcpClient client = SockServer.AcceptTcpClient();
+
+            data = null;
+
+            NetworkStream stream = client.GetStream();
+
+            int i;
+
+            // flag for loop
+            bool Alldone = false;
+            // End of Transmission character 
+            char theChar = '\u0004';
+            string ch = theChar.ToString();
+
+            while (!Alldone)
+            {
+              i = stream.Read(bytes, 0, bytes.Length);
+              // translate stream to string data;
+              data += System.Text.Encoding.ASCII.GetString(bytes);
+              if ((data.Contains(ch)) || (i == 0))
+                Alldone = true;
+            }
+
+            int POS = data.IndexOf(ch);
+            data = data.Substring(0, POS);
+            // strip off EOT character
+
+            // CODE RUN WHEN REQUEST IS RECEIVED COMMENTED OUT
+            // create requestprocessing object here and hand off
+
+            //RequestHandler handler = new RequestHandler(data);
+            //string response = handler.ProcessRequest() + ch;
+
+            //// send back result
+            //byte[] ret = System.Text.Encoding.ASCII.GetBytes(response);
+            //stream.Write(ret, 0, ret.Length);
+
+
+          }
+        }
+
+      }
+      catch (SocketException e)
+      {
+        Console.WriteLine(e.ToString());
+      }
+      finally
+      {
+        SockServer.Stop();
+      }
+    }


More information about the mono-bugs mailing list