서버 응용 프로그램에서 두 번째 응답을 받아야합니다. 서버 응용 프로그램에 처음 연결할 때 회신을받습니다. 그러나 다른 메시지를 보내려고하면받을 수 없습니다.TcpClient 및 StreamReader를 사용하여 둘 이상의 메시지를받을 수 없습니다.
해결책을 찾으려고했지만 아무 것도 찾을 수 없습니다. 문제는 내 독자의 포인터가 아직 끝났다고 생각합니다. 그래서 다음 답장을 읽을 수 없습니다. 여기 내 코드입니다 :
public static void XConn()
{
TcpClient client = new TcpClient();
client.Connect("xxx.xxx.xxx.xxx",xx); // i cant show the IP sorry
Stream s = client.GetStream();
StreamReader sr = new StreamReader(s);
StreamWriter sw = new StreamWriter(s);
String r = "";
sw.AutoFlush = true;
sw.WriteLine("CONNECT\nlogin:xxxxxxx \npasscode:xxxxxxx \n\n" + Convert.ToChar(0)); // cant show also
while(sr.Peek() >= 0)
{
r = sr.ReadLine();
Console.WriteLine(r);
Debug.WriteLine(r);
if (r.ToString() == "")
break;
}
sr.DiscardBufferedData();
//get data needed, sendMsg is a string containing the message i want to send
GetmsgType("1");
sw.WriteLine(sendMsg);
// here i try to receive again the 2nd message but it fails =(
while(sr.Peek() >= 0)
{
r = sr.ReadLine();
Console.WriteLine(r);
Debug.WriteLine(r);
if (r.ToString() == "")
break;
}
s.Close();
Console.WriteLine("ok");
}
어떤 프로토콜은 이것이다 : 당신이 정말로 시간 제한을 설정하거나 예외를 잡기에 대해 걱정할 필요가 없습니다 경우에도 작동 할 수 다음? –
프로토콜? 너 무슨 뜻이야? 메시지가 전송되었다는 뜻입니까? –
예 - 보내고받은 메시지의 지정된 형식은 무엇입니까? 그것은 CONNECT \ nlogin ... \ npassword ... \ n \ n \ 0으로되어 있습니까? 또한, 어떻게 실패하고 있습니까? 오류가 발생 했습니까? 아니면 아무 것도 인쇄되지 않습니다. –