SmallSockets 라이브러리 (http://smallsockets.sourceforge.net/)를 사용하여 앱을 만들고 있습니다. 22 :SmallSockets를 사용하여 소켓에서 읽으면 내 응용 프로그램이 손상됩니다.
2009-10-24 18 : 여기
#import "MAController.h" #import "Socket.h" @implementation MAController - (IBAction)doRequest:(id)sender { //Initialize NSURL *uUrl = [[NSURL alloc] initWithString:[tfHost stringValue]]; int iPort = [[uUrl port] intValue]; NSString *sHost = [uUrl host]; //Check if(sHost == NULL) { //Invalid Host name NSLog(@"Invalid Host name"); NSAlert *aInvalidHost = [[[NSAlert alloc] init] autorelease]; [aInvalidHost addButtonWithTitle:@"Ok"]; [aInvalidHost setInformativeText:@"Invalid Host name"]; [aInvalidHost setMessageText:@"You have entered an invalid host name. Please enter a valid host name."]; [aInvalidHost setAlertStyle:NSInformationalAlertStyle]; [aInvalidHost beginSheetModalForWindow:wMain modalDelegate:self didEndSelector:NULL contextInfo:nil]; return; } if(iPort == 0) { iPort = 80; } //Create request NSString *sRequest = [[NSString alloc] initWithString:[tvRequest string]]; //Create socket Socket *sSocket = [Socket socket]; NSLog(@"Connecting..."); [sSocket connectToHostName:sHost port:iPort]; //Write request NSLog(@"Writing..."); [sSocket writeString:sRequest]; //Read response NSLog(@"Reading..."); NSMutableData *mdResponse = [[[NSMutableData alloc] init] autorelease]; //IT CRASHES RIGHT HERE while([sSocket readData:mdResponse]) { NSLog(@"Read."); } //Display response NSLog(@"Displaying..."); NSString *sResponse = [[[NSString alloc] initWithData:mdResponse encoding:[NSString defaultCStringEncoding]] autorelease]; [tvResponse setString:sResponse]; [mdResponse release]; [sSocket release]; } @end
내 디버거 내가 doRequest 동작을 발사 버튼을 클릭 한 후 말씀입니다 :
이 코드가 19.197 iDebug HTTP [4836 : a0f] 연결 중 ...
2009-10-24 18 : 22 : 19.399 쓰기 ...
2009-10-24 18 : 22 : 19.400 iDebug HTTP [4836 : a0f] 읽기 ...
호스트 이름 http://www.example.com
이며 포트는 80
사람이 나를 설명 할 수 있습니까? 미리 감사드립니다.
방화벽이 설치되어 있지 않습니다.