iphone 응용 프로그램에서 서버가 프로그래밍 방식으로 활성화되어 있는지 여부를 확인하고 싶습니다.iphone에서 응답 시간 (ping)을 프로그래밍 방식으로 계산하는 방법
서버의 응답 시간을 어떻게 계산합니까?
핑 (ping)에 대해 들어 본 내용은 무엇입니까?
iphone 응용 프로그램에서 서버가 프로그래밍 방식으로 활성화되어 있는지 여부를 확인하고 싶습니다.iphone에서 응답 시간 (ping)을 프로그래밍 방식으로 계산하는 방법
서버의 응답 시간을 어떻게 계산합니까?
핑 (ping)에 대해 들어 본 내용은 무엇입니까?
예를 들어 Apple http://developer.apple.com/iphone/library/samplecode/Reachability/index.html의 도달 가능성을 사용하여 서버에 연결을 시도하고 NSTimer
을 사용하여 응답 시간을 측정 할 수 있습니다. 하지만 ping
명령만큼 정확하지는 않습니다.
서버에서 응답을 얻으려면 먼저 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 ];
}
}
안녕하세요.이 참조 할 수 있습니다, 도와 주셔서 너무 감사합니다. 당신은 서버에서 응답을 얻기 위해 취한 시간을 어떻게 계산합니까? – SriPriya
내가 말했듯이, NSTimer;) 문서를 찾지 만 기본적으로 Reachability를 호출하기 전에 화재 메시지를 받고 도달 후 timeInterval 속성을 사용하여 시간을 계산합니다. –
감사합니다. – SriPriya