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("", 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 + "");

            //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

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

Use a timer to poll the sockets:
[URL="System.Threading.Timer"]System.Threading.Timer[/URL] or

Jump to Post

All 2 Replies

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