Exemple #1
0
        protected override void OnStart(string[] args)
        {
            FEvent = new OnEventDelegate(Event);
            FEchoLog = new StreamWriter(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "\\EchoLog.txt");

            FServer = new SocketServer(CallbackThreadType.ctWorkerThread, new EchoSocketService.EchoSocketService(FEvent), DelimiterType.dtMessageTailExcludeOnReceive, Encoding.GetEncoding(1252).GetBytes("ALAZ"), 1024 * 2, 1024 * 16);
            FServer.AddListener("Commom Port - 8090", new IPEndPoint(IPAddress.Any, 8090), EncryptType.etRijndael, CompressionType.ctNone, new EchoCryptService.EchoCryptService(), 50, 3);
            FServer.Start();
        }
        protected override void OnStart(string[] args)
        {
            chatServer = new SocketServer(CallbackThreadType.ctWorkerThread, new ChatSocketService.ChatSocketService());

            chatServer.Context.DelimiterEncrypt = new byte[] { 0xAA, 0xFF, 0xAA };
            chatServer.Context.DelimiterType = DelimiterType.dtMessageTailExcludeOnReceive;

            chatServer.Context.SocketBufferSize = 1024;
            chatServer.Context.MessageBufferSize = 512;

            //----- Socket Listener!
            SocketListener listener = chatServer.AddListener("Char Server", new IPEndPoint(IPAddress.Any, 8090));

            listener.AcceptThreads = 3;
            listener.BackLog = 50;

            listener.Context.CompressionType = CompressionType.ctNone;
            listener.Context.EncryptType = EncryptType.etRijndael;
            listener.Context.CryptoService = new ChatCryptService.ChatCryptService();

            chatServer.Start();
        }
Exemple #3
0
        private static void Main(string[] args)
        {
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);

            //----- Socket Server!
            OnEventDelegate FEvent = new OnEventDelegate(Event);

            SocketServer echoServerProvider = new SocketServer(CallbackThreadType.ctWorkerThread, new EchoSocketService.EchoSocketService(FEvent));

            echoServerProvider.Context.DelimiterEncrypt = new byte[] { 0xFF, 0x00, 0xFE, 0x01, 0xFD, 0x02 };
            echoServerProvider.Context.DelimiterType = DelimiterType.dtMessageTailExcludeOnReceive;

            echoServerProvider.Context.SocketBufferSize = 1024;
            echoServerProvider.Context.MessageBufferSize = 2048;

            echoServerProvider.Context.IdleCheckInterval = 60000;
            echoServerProvider.Context.IdleTimeOutValue = 120000;

            //----- Socket Listener!
            SocketListener listener = echoServerProvider.AddListener("Commom Port - 8090", new IPEndPoint(IPAddress.Any, 8090));

            listener.AcceptThreads = 3;
            listener.BackLog = 100;
            listener.Context.Host = echoServerProvider;
            listener.Context.EncryptType = EncryptType.etNone;
            listener.Context.CompressionType = CompressionType.ctNone;
            listener.Context.CryptoService = new EchoCryptService.EchoCryptService();

            echoServerProvider.Start();

            Console.WriteLine("Started!");
            Console.WriteLine("----------------------");

            int iot = 0;
            int wt = 0;

            ThreadPool.GetAvailableThreads(out wt, out iot);
            Console.WriteLine("Threads Work - " + wt.ToString());
            Console.WriteLine("Threads I/O  - " + iot.ToString());

            string s;

            do
            {
                s = Console.ReadLine();

                if (s.Equals("g"))
                {
                    ThreadPool.GetAvailableThreads(out wt, out iot);
                    Console.WriteLine("Threads Work " + iot.ToString());
                    Console.WriteLine("Threads I/O  " + wt.ToString());
                }
            } while (s.Equals("g"));

            try
            {
                echoServerProvider.Stop();
                echoServerProvider.Dispose();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            echoServerProvider = null;

            Console.WriteLine("Stopped!");
            Console.WriteLine("----------------------");
            Console.ReadLine();
        }
Exemple #4
0
        private static void Main(string[] args)
        {
            SocketServer chatServer = new SocketServer(CallbackThreadType.ctWorkerThread, new ChatSocketService.ChatSocketService());

            chatServer.Context.DelimiterEncrypt = new byte[] { 0xAA, 0xFF, 0xAA };
            chatServer.Context.DelimiterType = DelimiterType.dtMessageTailExcludeOnReceive;

            chatServer.Context.SocketBufferSize = 1024;
            chatServer.Context.MessageBufferSize = 512;

            //----- Socket Listener!
            SocketListener listener = chatServer.AddListener("Char Server", new IPEndPoint(IPAddress.Any, 8090));

            listener.AcceptThreads = 3;
            listener.BackLog = 50;

            listener.Context.CompressionType = CompressionType.ctNone;
            listener.Context.EncryptType = EncryptType.etRijndael;
            listener.Context.CryptoService = new ChatCryptService.ChatCryptService();

            chatServer.Start();

            Console.WriteLine(" Chat Server Started!");
            Console.WriteLine("--------------------------------------");

            string key;
            int iot = 0;
            int wt = 0;

            do
            {
                Console.WriteLine(" Press T <ENTER> for Threads");
                Console.WriteLine(" Press C <ENTER> for Clients");
                Console.WriteLine(" Press S <ENTER> for Stop Server");
                Console.WriteLine("--------------------------------------");
                Console.Write(" -> ");

                key = Console.ReadLine().ToUpper();

                if (key.Equals("T"))
                {
                    ThreadPool.GetAvailableThreads(out wt, out iot);

                    Console.WriteLine("--------------------------------------");
                    Console.WriteLine(" I/O Threads " + iot.ToString());
                    Console.WriteLine(" Worker Threads " + wt.ToString());
                    Console.WriteLine("--------------------------------------");
                }

                if (key.Equals("C"))
                {
                    ISocketConnection[] infos = chatServer.GetConnections();

                    Console.WriteLine("\r\n--------------------------------------");
                    Console.WriteLine(" " + infos.Length.ToString() + " user(s)!\r\n");

                    foreach (ISocketConnection info in infos)
                    {
                        Console.WriteLine(" Connection Id " + info.Context.ConnectionId.ToString());
                        Console.WriteLine(" User Name " + ((ConnectionData)info.Context.UserData).UserName);
                        Console.WriteLine(" Ip Address " + info.Context.RemoteEndPoint.Address.ToString());

                        Console.WriteLine("--------------------------------------");
                    }
                }
            } while (!key.Equals("S"));

            Console.WriteLine(" Chat Server Stopping!");
            Console.WriteLine("--------------------------------------");

            try
            {
                chatServer.Stop();
                chatServer.Dispose();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            chatServer = null;

            Console.WriteLine(" Chat Server Stopped!");
            Console.WriteLine("--------------------------------------");

            Console.ReadLine();
        }
 protected override void OnStop()
 {
     chatServer.Stop();
     chatServer.Dispose();
     chatServer = null;
 }