I have the following command class:
namespace socketTest
{
public class Command
{
// Hashtable to store strings and delegate
private Hashtable commands = new Hashtable();
private delegate void function ( );
// New commands created
public Command()
{
// Associate our delegates with strings
commands.Add ( "shutdown", new function ( doShutdownServer ) );
}
public void test(string testString )
{
IDictionaryEnumerator enumerator = commands.GetEnumerator();
while (enumerator.MoveNext())
if (enumerator.Key.ToString ( ) == testString)
((function)enumerator.Value)();
}
private void doShutdownServer ( )
{
}
}
}
that is called from my socket class:
Command command = new Command();
command.test ( "shutdown" );
Basically what I want to happen is my socket class sends a string to my command class. This string is an index to a function. In this case the function that will be called is doShutdownServer. What I want this function to do is call my server.stop ( ) method but I am unsure of how to do this. My server class is created in my main class. Any ideas on how I could do this would be cool. Thanks.