예제 #1
0
        private static void BatchSendRequestAdd(StringClient client)
        {
            int v1 = new Random().Next(3, 9);

            int[] v2 = new int[] { 1, 2, 3, 4, 5 };
            foreach (int i in v2)
            {
                Task.Factory.StartNew(() =>
                {
                    try
                    {
                        log4j.Info(string.Format("RequestAdd {0} {1}", v1, i));
                        //Task<Data.ResponseAdd> responseAdd = client.RequestAddAsync(v1, i);
                        //log4j.Info(string.Format("ResponseAdd {0} + {1} = {2}", v1, i, responseAdd.Result.Result));

                        Data.ResponseAdd response = client.RequestAdd(v1, i);
                        log4j.Info(string.Format("responseAdd: {0} + {1} = {2}", v1, i, response.Result));
                    }
                    catch (Exception ex)
                    {
                        log4j.Info(string.Format("RequestAdd {0} {1} {2}", v1, i, ex.Message));
                    }
                });
            }
        }
예제 #2
0
        static void Main(string[] args)
        {
            log4j.Info("Start Main");
            System.Net.IPEndPoint endpoint = new IPEndPoint(new IPAddress(new byte[] { 127, 0, 0, 1 }), 2012);

            StringClient client = new StringClient();

            var connected = client.ConnectAsync(endpoint);

            string cmd = "";

            while (cmd != "q")
            {
                if (cmd != "")
                {
                    // Server Command
                    // RequestEcho text
                    // RequestAdd 2 1
                    byte[] data = Encoding.UTF8.GetBytes(cmd + "\r\n");
                    //client.Send(data, 0, data.Length);
                    log4j.Info("sending command: " + cmd);
                    client.Send(data);
                }
                cmd = Console.ReadLine();
            }
            client.Close();
        }
예제 #3
0
        public override void ExecuteCommand(StringClient session, StringPackageInfo commandInfo)
        {
            log4j.Debug("ResponseAdd: " + commandInfo.Body);

            // after received data, pass the data to EventHandler
            Data.ResponseAdd responseAdd = Newtonsoft.Json.JsonConvert.DeserializeObject <Data.ResponseAdd>(commandInfo.Body);
            session.PushToResponseAddHandler(responseAdd);
        }
예제 #4
0
        private void button1_Click(object sender, EventArgs e)
        {
            
            StringClient host = new StringClient(); // proxy översätter 
            //så att jag tror att min klass TextFormatClient är i mitt projekt

            //Interfacet -> vårt projekt via proxy
            var input = textBox1.Text;
            label1.Text = input;


        }
예제 #5
0
 public override void ExecuteCommand(StringClient session, StringPackageInfo commandInfo)
 {
     log4j.Debug("ResponseAdd: " + commandInfo.Body);
     try
     {
         // after received data, pass the data to EventHandler
         TcpClientServer.Data.ResponseAdd responseAdd = Newtonsoft.Json.JsonConvert.DeserializeObject <TcpClientServer.Data.ResponseAdd>(commandInfo.Body);
         session.PushToResponseAddHandler(responseAdd);
     }
     catch (Exception ex)
     {
         log4j.Error("", ex);
     }
 }
예제 #6
0
        public async Task Connect(ConnectionSettings settings)
        {
            if (_session != null)
            {
                throw new InvalidOperationException("Cannot connect because the client is already connected");
            }

            _commonClient       = new CommonClient();
            _hashClient         = new HashClient();
            _listClient         = new ListClient();
            _scriptClient       = new ScriptClient();
            _stringClient       = new StringClient();
            _transactionClient  = new TransactionClient();
            _setClient          = new SetClient();
            _subscriptionClient = new SubscriptionClient();
            _session            = await _commonClient.Connect(settings).ConfigureAwait(false);

            if (!_session.IsOpen)
            {
                throw new IOException("Session could not be opened");
            }

            OnConnected?.Invoke(this);
        }
예제 #7
0
 public override void ExecuteCommand(StringClient session, StringPackageInfo commandInfo)
 {
     log4j.Info("ResponseAdd: " + commandInfo.Body.Trim());
 }
예제 #8
0
        public override void ExecuteCommand(StringClient session, StringPackageInfo commandInfo)
        {
            log4j.Info("ResponseEcho: " + commandInfo.Body);

            session.PushToResponseEchoHandler(commandInfo.Body);
        }
예제 #9
0
        static void Main(string[] args)
        {
            log4j.Info("Start Main");
            System.Net.IPEndPoint endpoint = new IPEndPoint(new IPAddress(new byte[] { 127, 0, 0, 1 }), 2012);

            StringClient client = new StringClient();

            var connected = client.ConnectAsync(endpoint);

            // test Command RequestAdd
            //BatchSendRequestAdd(client);

            string cmd = "";

            while (cmd != "q")
            {
                if (cmd == "1")
                {
                    int a = 4;
                    int b = 4;
                    try
                    {
                        //Task<Data.ResponseAdd> response = client.RequestAddAsync(a, b);
                        //log4j.Info(string.Format("responseAdd: {0} + {1} = {2}", a, b, response.Result.Result));
                        Task t1 = Task.Factory.StartNew(() =>
                        {
                            Data.ResponseAdd response = client.RequestAdd(a, b);
                            log4j.Info(string.Format("responseAdd: {0} + {1} = {2}", a, b, response.Result));
                        });
                        //client.Send(Encoding.UTF8.GetBytes("RequestEcho abcdefg\r\n"));
                        //client.Send(Encoding.UTF8.GetBytes(Data.Cmd.MyCommand.RequestEcho.ToString() + " abcdefg\r\n"));
                        client.RequestEcho("aaasslslslsl");
                        t1.Wait();
                    }
                    catch (TimeoutException ex)
                    {
                        log4j.Info("TimeOut", ex);
                    }
                    catch (Exception ex)
                    {
                        log4j.Info("error", ex);
                    }
                }
                else if (cmd == "2")
                {
                    //just to check and see did we remove the callback correctly!
                    client.HandlerCount();
                }
                else if (cmd == "3")
                {
                    BatchSendRequestAdd(client);
                }
                //else if (cmd != "")
                //{
                //    // Server Command
                //    // RequestEcho text
                //    byte[] data = Encoding.UTF8.GetBytes(cmd + "\r\n");
                //    //client.Send(data, 0, data.Length);
                //    log4j.Info("sending raw command: " + cmd);
                //    client.Send(data);
                //}
                cmd = Console.ReadLine();
            }
            client.Close();
        }