서버로 작동하는 프로그램을 작성했습니다. "accept"가 프로그램을 차단하고 있음을 알았습니다. 이 문장을 사용하여 프로그램을 차단하지 못하도록 막을 내리고 싶었지만 여전히 발생합니다. 아무도 도와 줄 수 있습니까? 우편 번호 감사내 스레드 프로그램 블록
-(IBAction)Connetti{
if(switchConnessione.on){
int port = [fieldPort.text intValue];
labelStatus.text = [[NSString alloc] initWithFormat:@"Il Server è attivo"];
server_len = sizeof(server);
server.sin_family = AF_INET;
server.sin_port = htons((u_short)port);
server.sin_addr.s_addr = INADDR_ANY;
sd = socket (AF_INET, SOCK_STREAM, 0);
bind(sd, (struct sockaddr*)&server, sizeof(server));
listen(sd, 1);
[NSThread detachNewThreadSelector:@selector(startThreadAccept) toTarget:self withObject:nil];
}
else {
labelStatus.text = [[NSString alloc] initWithFormat:@"Server non attivo"];
switchChat.on = FALSE;
switchChat.enabled = FALSE;
}
}
-(void)startThreadAccept{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc]init];
[self performSelectorOnMainThread:@selector(acceptConnection) withObject:nil waitUntilDone:NO];
[pool release];
}
-(void)acceptConnection{
new_sd = accept(sd, (struct sockaddr*)&server, &server_len);
labelStatus.text = [[NSString alloc] initWithFormat:@"Ho accettato una connessione:%d", new_sd];
switchChat.enabled = TRUE;
}
크래시 또는 차단합니까? 질문의 제목과 본문이 일치하지 않습니다. –