Greetings, I've got custom Telnet client in C#. I am using it to communicate with IMAP servers. It works as just write command, then get response. Test code:
Telnet tc = new Telnet();
// setup server credentials
const string server = "pop.nexlink.net";
const int port = 140;
const int timeout = 70;
// establish server connection
tc.Setup(server, port, timeout);
// test initial server response
Console.WriteLine(tc.output);
// set-up a few commands to send
var array = new[] { "USER [email protected]", "PASS password", "QUIT" };
// while connected to server
if (tc.IsConnected)
{
foreach (string str in array)
{
// Show command on console
Console.WriteLine(str);
// Write to Stream
tc.WriteLine(str);
// Read from Stream
tc.Read();
// Test the Stream output
Console.Write(tc.output);
}
}
// close connection
tc.Disconnect();
Output from calling above code is:
- USER [email protected]
- +OK Welcome to the Atmail POP3 server - Login with user@domain.
- +OK Password required.
- PASS password
- QUIT
- +OK logged in.
- +OK Bye-bye.
This is a simplistic example, however it shows a problem of race condition. Output from line nr.6 should appear before nr. 5
Q: How to handle that ?