In a button click event I need to send 5 different commands recieve each output one by one.

My code for only one command is (its works):

TcpClient socketForServer;
            socketForServer = new TcpClient("127.0.0.1", 2211);
            NetworkStream networkStream = socketForServer.GetStream();
            System.IO.StreamReader streamReader = new System.IO.StreamReader(networkStream);
            System.IO.StreamWriter streamWriter = new System.IO.StreamWriter(networkStream);

            string command = command.Text;
            streamWriter.WriteLine(command + "");
            streamWriter.Flush();

            //wait for and retrieve response

           string outputString;
   
           socketForServer.ReceiveTimeout = 5000;
           outputString = streamReader.ReadToEnd();
           textxml.Text = outputString;
...

For example:

send command1 socket recieve output1 in textbox1, then take value from xml
send command2 recieve ouput2 in textbox2, then take value from xml
etc...

My difficult is to create this kind of "cycle" of command, result in only one button click event. I need cycle because the other software from send the command only receive one command then gives the output, one by one.

Thanks in advance

Recommended Answers

All 2 Replies

Any ideas? I´m a bit confused with this... thank you

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.