인사말, C#에서 사용자 지정 텔넷 클라이언트가 있습니다. IMAP 서버와 통신하는 데 사용하고 있습니다. 쓰기 명령으로 작동 한 다음 응답을받습니다. 테스트 코드 : 코드 위의 호출에서스트림에 읽기/쓰기를 동기화하는 방법은 무엇입니까?
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();
출력은 다음과 같습니다 Atmail의 POP3 서버에
- 사용자 [email protected]
- + OK 오신 것을 환영합니다 - 사용자 @ 도메인으로 로그인합니다.
- + 비밀번호가 필요합니다.
- PASS 암호
- 는 + OK
- 가 로그인 종료합니다.
- + OK 안녕.
이것은 단순한 예이지만 경쟁 조건의 문제를 보여줍니다. nr.6 라인 출력은 nr. 5
Q : 어떻게 처리합니까?
잘하고있는 것 같습니다. 서버는 사용자 로그인을 마치기 전에 종료 메시지를 수신합니다. –
가능합니다. 응답은 다소 임의적입니다. 연결 속도, 서버 응답 시간, 반환 할 데이터 양에 따라 다릅니다. 더 커다란 흐름을 요구하는 명령이 더 많아지면 정말 지저분 해집니다. 일반적으로 읽기는 쓰기보다 훨씬 느립니다. – asyncpro