[Mono-list] Hello

Terry thenn@sbcglobal.net
Mon, 26 May 2003 12:17:02 -0500


It behaves the same whether the server socket has accepted any connections
or not.  In other words, it fails to interrupt the
TcpListener.AcceptSocket() call when I call Stop().

Maybe I should ask if I'm setting up the socket properly and shutting it
down properly.

At startup, the main app thread creates a new thread to handle the incoming
connection requests.

public void start(uint nListenPort)
{
  m_nListenPort = nListenPort;
  serverThread = new Thread(new ThreadStart(mainServerProc) );
  serverThread.Name = "SISH Server Thread";
  serverThread.Start();
}

The "mainServerProc" (with some error handling code removed) just creates
the Listener, calls Start() and then AcceptSocket().

private void mainServerProc()
{
  // Create the main socket and listen for connections
  m_tcpListener = new TcpListener((int)m_nListenPort);

  m_tcpListener.Start();

  try
  {
    while (true)
    {
      //Accept the pending client connection and return a TcpClient
initialized for communication.
      Socket clientSocket = m_tcpListener.AcceptSocket();

      ClientConnection client = new ClientConnection(m_app, clientSocket);

     m_app.handleNewConnection(client);
    }
  }
  catch (SocketException e)
  {
    // handle exception
  }
  catch (Exception e)
  {
    // handle exception
  }
}

... and when I need to shut down, I'm attempting to "Stop" the TcpListener
from a different thread.  Perhaps this is the problem???

public void shutdown()
{
  Console.WriteLine("  ===>  Shutting down server...");

  m_tcpListener.Stop();
  m_tcpListener = null;

  serverThread.Join();
  Console.WriteLine("  <===  server shut down successfully ...");
}

What happens is after calling "Stop()" the "AcceptSocket()" call is not
interrupted, so the "mainServerProc()" thread never exits.  This happens
regardless of whether there have been any connections accepted.

This does work on Windows, so I'm wonding if my socket setup is incorrect or
if this might be a bug in the 0.24 mono release.  If it comes down to it, I
guess I'll have to setup a shutdown event so I don't have to rely on the
ability to interrupt the accept call.

Thanks,
Terry

-----Original Message-----
From: mono-list-admin@lists.ximian.com
[mailto:mono-list-admin@lists.ximian.com]On Behalf Of Jeremiah McElroy
Sent: Sunday, May 25, 2003 9:01 PM
To: mono-list@lists.ximian.com
Subject: RE: [Mono-list] Hello


>From reading the MS Documentation (.NET SDK 1.1, VS.NET 2003 EA for those
who are interested in these things), it says something along the lines of
'you must close each accepted connection individually.'

What I took this to mean is that you will have to build a stack of your own
for all client connections and then  when you call TcpListener.Stop(),
you'll have to loop through your stack and Stop() all of those connections
as well.  I could be wrong on the subject, I usually deal with POP3 and SMTP
or raw nasty sockets that die quickly and don't persist any kind of state.


Later,

Jeremiah McElroy

We all learn by sharing what we know
-----Original Message-----
From: mono-list-admin@lists.ximian.com
[mailto:mono-list-admin@lists.ximian.com] On Behalf Of Terry
Sent: Saturday, May 24, 2003 10:51 PM
To: mono-list@lists.ximian.com
Subject: [Mono-list] Hello


Hello all,

I just thought I'd introduce myself to the list before asking questions.
I'm a software developer by profession and I work on a free game server tool
in my spare time.  After adding a server-side portion to my app, I got
several requests for Linux support and I started looking at C/C++ and C# as
an option.  A co-worker told me about Mono and I started working with the
0.23 release.  Great job!  I'm very impressed with the progress so far -
it's a huge thrill for me to take a binary and watch it work on both Windows
and Linux.  I'm very excited about the future!

It's a simple TCP server that allows admins to have remote access to their
game consoles.  So far, it's working pretty well, but I've come across a
couple things that, as far as I can tell, should be operational, but isn't
working for me.

I just installed 0.24 on RH8 without garbage collection.  The "make" failed
with an invalid "-lgc" option (problem with configure?).  I've run into two
problems with TcpListener and FileSystemWatcher....

[Newbie flame suit on]
I have a thread that calls "TcpListener.AcceptSocket()" and keeps looping
handling the new connection requests.  This works great.  However, when I go
to shut down, I call "TcpListener.Stop()" from a different thread and then
"Join" to wait for the server thread to exit.  It never exists because the
server thread is still blocking on the "AcceptSocket()" call.  Shouldn't
calling "Stop" interrupt the "AcceptSocket()" call?  Or is that an invalid
assumption?

Also, I want to use FileSystemWatcher to watch for changes to my cfg files,
but after setting things up, it appears that after making changes to files
in the watched directory, the changed event never fires.  It does work on
Windows, however.  I do not get an exception - nothing happens.  I'm using
the "FileSystemWatcher/FileSystemEventHandler" method rather than the
"WaitForChanged" method (I see that's not implemented yet :-).
[Newbie flame suit off]

I can post code if it's relevant...

Thanks,
Terry