2010-12-11 4 views

답변

1

예를 들어 Apple http://developer.apple.com/iphone/library/samplecode/Reachability/index.html의 도달 가능성을 사용하여 서버에 연결을 시도하고 NSTimer을 사용하여 응답 시간을 측정 할 수 있습니다. 하지만 ping 명령만큼 정확하지는 않습니다.

+0

안녕하세요.이 참조 할 수 있습니다, 도와 주셔서 너무 감사합니다. 당신은 서버에서 응답을 얻기 위해 취한 시간을 어떻게 계산합니까? – SriPriya

+0

내가 말했듯이, NSTimer;) 문서를 찾지 만 기본적으로 Reachability를 호출하기 전에 화재 메시지를 받고 도달 후 timeInterval 속성을 사용하여 시간을 계산합니다. –

+0

감사합니다. – SriPriya

-2

서버에서 응답을 얻으려면 먼저 Thomas가 말한 것처럼 Reachability를 구현하여 네트워크 연결이 가능한지 확인하십시오.

이제 네트워크에 연결되어 있으면 서버를 요청하고 아래에 설명 된대로 응답을 수신 할 수 있습니다.

-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response{ 

     NSHTTPURLResponse *httpResponse; 
     httpResponse = (NSHTTPURLResponse *)response; 
     int statusCode = [httpResponse statusCode]; 
     NSString *serverResponse = [NSString stringWithFormat:@"%d", statusCode]; 
     NSLog (@ "status code =% d" , statusCode); 
     if(statusCode!=200){ 
      UIAlertView * Alert = [[ UIAlertView alloc ] initWithTitle : @"Problem" 
                   Message : serverResponse 
                   delegate : nil 
                cancelButtonTitle : @ " OK " 
                otherButtonTitles : nil ]; 
      [Alert Show ]; 
      [Alert Release ]; 

     } 
} 

당신이 List of HTTP Status Code

관련 문제