Example #1
0
        private static void ExceptionHandler(Exception oBug)
        {
            System.Console.Out.WriteLine("Error: " + oBug.Message);
            Exception oEx = myServer.GetLastException();

            if (oEx != null)
            {
                System.Console.Out.WriteLine("Error: " + oEx.Message);
            }
        }
Example #2
0
        // Lag nghe Errors
        private void ExceptionHandler(Exception oBug)
        {
            log4net.Error(oBug.Message);
            RegisterLog(oBug.Message, "Error", oBug.Source, oBug.StackTrace);
            Exception oEx = myServer.GetLastException();

            if (oEx != null)
            {
                log4net.Error(oBug.Message);
                RegisterLog(oBug.Message, "Error", oBug.Source, oBug.StackTrace);
            }
        }
Example #3
0
 static void Main(string[] args)
 {
     try
     {
         if (args.Length == 1)
         {
             myServer = new XYNetServer("", Convert.ToInt32(args[0]), 5, 10);
             myServer.SetConnectionFilter(new ConnectionFilterDelegate(Test.ConnectionFilter));
             myServer.SetExceptionHandler(new ExceptionHandlerDelegate(Test.ExceptionHandler));
             myServer.SetBinaryInputHandler(new BinaryInputHandlerDelegate(Test.BinaryInputHandler));
             myServer.SetStringInputHandler(new StringInputHandlerDelegate(Test.StringInputHandler));
             if (myServer.StartServer() == false)
             {
                 throw myServer.GetLastException();
             }
             System.Console.Out.WriteLine("Waiting for connections on Port {0}", args[0]);
             Thread.Sleep(600000);
             System.Console.Out.WriteLine("Thread count: " + myServer.GetThreadCount().ToString());
             System.Console.Out.WriteLine("Client count: " + myServer.GetClientCount().ToString());
             myServer.StopServer();
             System.Console.Out.WriteLine("Done!");
         }
         else if (args.Length == 2)
         {
             const int     nSize    = 100;
             const int     nPause   = 10;
             XYNetClient[] pClients = new XYNetClient[nSize];
             for (int i = 0; i < nSize; i++)
             {
                 pClients[i] = new XYNetClient(args[0], Convert.ToInt32(args[1]));
                 if (pClients[i].Connect() == false)
                 {
                     throw pClients[i].GetLastException();
                 }
                 Thread.Sleep(nPause);
             }
             for (int i = 0; i < nSize; i++)
             {
                 if (pClients[i].SendStringData("Text sent as string data") == false)
                 {
                     throw pClients[i].GetLastException();
                 }
                 Thread.Sleep(nPause);
             }
             for (int i = 0; i < nSize; i++)
             {
                 Object[] pData = pClients[i].ReceiveData();
                 if (pData == null)
                 {
                     throw pClients[i].GetLastException();
                 }
                 String sData = (String)(pData[1]);
                 System.Console.Out.WriteLine("String data from server: " + sData);
                 Thread.Sleep(nPause);
             }
             for (int i = 0; i < nSize; i++)
             {
                 if (pClients[i].SendBinaryData(XYNetCommon.StringToBinary("Text sent as binary data")) == false)
                 {
                     throw pClients[i].GetLastException();
                 }
                 Thread.Sleep(nPause);
             }
             for (int i = 0; i < nSize; i++)
             {
                 Object[] pData = pClients[i].ReceiveData();
                 if (pData == null)
                 {
                     throw pClients[i].GetLastException();
                 }
                 Byte[] pData2 = (Byte[])(pData[0]);
                 System.Console.Out.WriteLine("Binary data from server: " + XYNetCommon.BinaryToString(pData2));
                 Thread.Sleep(nPause);
             }
             for (int i = 0; i < nSize; i++)
             {
                 pClients[i].Reset();
             }
         }
         else
         {
             throw new Exception("Invalid number of arguments");
         }
     }
     catch (Exception oBug)
     {
         System.Console.Out.WriteLine("Error Type: " + oBug.GetType().Name);
         System.Console.Out.WriteLine("Error Message: " + oBug.Message);
         System.Console.Out.WriteLine("Error Source: " + oBug.Source);
         System.Console.Out.WriteLine("Error StackTrace: " + oBug.StackTrace);
         if (args.Length > 0)
         {
             System.Console.Out.WriteLine("arg0 = " + args[0]);
         }
         if (args.Length > 1)
         {
             System.Console.Out.WriteLine("arg1 = " + args[1]);
         }
     }
 }