Пример #1
0
        public void Setup()
        {
            Server = new TcpAppServer();
            Server.Start(25000);
            Server.ClientSignedIn   += Server_ClientSignedIn;
            Server.ClientSigningOut += Server_ClientSigningOut;
            Server.RegisterCommand("Custom_1", "Custom Command.", Custom1Callback);
            Server.RegisterQueuedCommand("Delay", "Custom Delay", (TcpAppInputCommand sender) =>
            {
                //Each connection execute command from different thread
                int delay = Convert.ToInt32(sender.Command.Parameter("duration").Value);
                //TestContext.Progress.WriteLine(sender.Command.Parameter("client").Value + " Sleep " + delay.ToString());
                Thread.Sleep(delay);
                sender.Status        = TcpAppCommandStatus.OK;
                sender.OutputMessage = "Delay Tick";
            },
                                         TcpAppParameter.CreateParameter("client", "client name"),
                                         TcpAppParameter.CreateParameter("duration", "Duration in ms"));
            Server.RegisterCommand("DelayNoQueue", "Custom Delay", (TcpAppInputCommand sender) =>
            {
                //Each connection execute command from different thread
                int delay = Convert.ToInt32(sender.Command.Parameter("duration").Value);
                //TestContext.Progress.WriteLine(sender.Command.Parameter("client").Value + " Sleep " + delay.ToString());
                Thread.Sleep(delay);
                sender.Status        = TcpAppCommandStatus.OK;
                sender.OutputMessage = "MAIN";
            },
                                   TcpAppParameter.CreateParameter("client", "client name"),
                                   TcpAppParameter.CreateParameter("duration", "Duration in ms"));
            Server.RegisterPluginType(typeof(TcpAppServerSimpleMath));


            Client = new TcpAppClient("localhost", 25000);
            Tcp    = new TcpClient("localhost", 25000);
        }
Пример #2
0
        public Form1()
        {
            InitializeComponent();
            Server                       = new TcpServer();
            Server.MaxClients            = 5;
            Server.ServerStarted        += Server_StateChanged;
            Server.ServerStopped        += Server_StateChanged;
            Server.ClientConnected      += Server_ClientConnected;
            Server.ClientDisconnected   += Server_ClientDisconnected;
            propertyGrid1.SelectedObject = Server;

            AppServer = new TcpAppServer()
            {
                WelcomeMessage = "Welcome to TCP Application Server. Copyright (C) Code Art Engineering."
            };
            AppServer.MaxClients          = 5;
            AppServer.ExecutionTimeout    = 1000;
            AppServer.ClientConnected    += AppServer_ClientConnected;
            AppServer.ClientDisconnected += AppServer_ClientDisconnected;
            AppServer.ClientSignedIn     += AppServer_ClientInitialized;
            AppServer.ClientSigningOut   += AppServer_ClientSigningOut;
            tcpClientsList1.AssignObject(AppServer);
            tcpAppServerQueue1.AssignObject(AppServer);

            //TCP Application Server Customization Test
            AppServer.RegisterCommand("CustomFunction", "Dummy Custom Function", customFunctionCallback);
            AppServer.RegisterCommand("CustomFunction2", "Dummy Custom Function with Parameter", customFunction2Callback,
                                      TcpAppParameter.CreateParameter("P1", "Parameter 1"),
                                      TcpAppParameter.CreateOptionalParameter("P2", "Parameter 2, optional.", "10"));
            AppServer.RegisterCommand("SlowCommand", "Command which take 10 seconds to complete. Simulate blocking!", SlowCommand);
            AppServer.RegisterQueuedCommand("SlowCommandQ", "Command which take 10 seconds to complete. Run in queue. Simulate blocking!", SlowCommand);

            CodeArtEng.Tcp.Tests.TcpAppServerSamplePlugin SamplePlugin = new CodeArtEng.Tcp.Tests.TcpAppServerSamplePlugin();
            AppServer.RegisterPluginType(typeof(CodeArtEng.Tcp.Tests.TcpAppServerSamplePlugin));
            AppServer.RegisterPluginType(typeof(CodeArtEng.Tcp.Tests.TcpAppServerSimpleMath));

            propertyGrid2.SelectedObject = AppServer;
        }