클라이언트와 서버 간의 통신을 구축했습니다. 그래서 두 개의 별도 프로젝트를 만들고 있습니다. 문제는 이것이 작동하지 않는다는 것입니다.C# TCP 문제가있는 클라이언트와 서버
서버 코드 :
private void Form1_Load(object sender, EventArgs e)
{
IPAddress ipaddress = IPAddress.Parse("127.0.0.1");
int port = 13000;
TcpListener server = new TcpListener(ipaddress, port);
server.Start();
while (true)
{
TcpClient client = server.AcceptTcpClient();
label1.Text = "That Connected to Server";
}
}
클라이언트 코드 : 콘솔 응용 프로그램에
private void Form1_Load(object sender, EventArgs e)
{
IPAddress ipaddress = IPAddress.Parse("127.0.0.1");
int port = 13000;
TcpClient obj = new TcpClient(ipaddress.ToString(), port);
while (true)
{
label1.Text = "connected";
}
}
이 코드는 잘 작동. 그러나 창문 형태로 일하지는 않습니다. 두 응용 프로그램을 모두 실행 중이지만 화면에 출력이 없습니다. 그것을 고치는 방법을 도와주세요. 사전
Windows 응용 프로그램은 ** 이벤트 구동 **입니다. 'Form.Load' 이벤트에'while (true)'루프를 넣으면 그 함수를 빠져 나오지 않을 것입니다. 그러면 인터페이스를 보지 못할 것입니다. 이 코드를 별도의 스레드에서 실행해야만 UI 스레드에'BeginInvoke' 결과가 생깁니다. –