다음을 통해 공유


PingReply 클래스

정의

상태 SendAsync 및 작업으로 Send 인한 데이터에 대한 정보를 제공합니다.

public ref class PingReply
public class PingReply
type PingReply = class
Public Class PingReply
상속
PingReply

예제

다음 코드 예제에서는 클래스를 사용하여 Ping ICMP 에코 요청을 동기적으로 보내고 응답을 표시하는 방법을 보여 줍니다.

using System;
using System.Net;
using System.Net.NetworkInformation;
using System.Text;

namespace Examples.System.Net.NetworkInformation.PingTest
{
    public class PingExample
    {
        // args[0] can be an IPaddress or host name.
        public static void Main (string[] args)
        {
            Ping pingSender = new Ping ();
            PingOptions options = new PingOptions ();

            // Use the default Ttl value which is 128,
            // but change the fragmentation behavior.
            options.DontFragment = true;

            // Create a buffer of 32 bytes of data to be transmitted.
            string data = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
            byte[] buffer = Encoding.ASCII.GetBytes (data);
            int timeout = 120;
            PingReply reply = pingSender.Send (args[0], timeout, buffer, options);
            if (reply.Status == IPStatus.Success)
            {
                Console.WriteLine ("Address: {0}", reply.Address.ToString ());
                Console.WriteLine ("RoundTrip time: {0}", reply.RoundtripTime);
                Console.WriteLine ("Time to live: {0}", reply.Options.Ttl);
                Console.WriteLine ("Don't fragment: {0}", reply.Options.DontFragment);
                Console.WriteLine ("Buffer size: {0}", reply.Buffer.Length);
            }
        }
    }
}
open System.Net.NetworkInformation
open System.Text

// args[0] can be an IPaddress or host name.
[<EntryPoint>]
let main args =
    let pingSender = new Ping()

    // Use the default Ttl value which is 128,
    // but change the fragmentation behavior.
    let options = PingOptions()
    options.DontFragment <- true

    // Create a buffer of 32 bytes of data to be transmitted.
    let data = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
    let buffer = Encoding.ASCII.GetBytes data
    let timeout = 120
    let reply: PingReply = pingSender.Send(args.[0], timeout, buffer, options)

    match reply.Status with
    | IPStatus.Success ->
        printfn "Address: %O" reply.Address
        printfn "RoundTrip time: %d" reply.RoundtripTime
        printfn "Time to live: %d" reply.Options.Ttl
        printfn "Don't fragment: %b" reply.Options.DontFragment
        printfn "Buffer size: %d" reply.Buffer.Length
        0
    | _ ->
        eprintfn "Error sending ping: %O" reply
        eprintfn "Error was: %O" reply.Status
        1

설명

클래스는 Ping 원격 컴퓨터에 ICMP(인터넷 제어 메시지 프로토콜) 에코 요청을 보내고 ICMP 에코 회신 메시지를 통해 컴퓨터에서 정보를 다시 수신하려고 시도합니다. 클래스는 Ping 클래스의 PingReply 인스턴스를 사용하여 해당 상태 및 요청을 보내고 회신을 받는 데 걸린 시간과 같은 작업에 대한 정보를 반환합니다.

메서드는 Send 클래스의 인스턴스를 PingReply 직접 반환합니다. 메서드는 SendAsync 메서드의 PingCompletedEventArgs 매개 변수에서 PingCompletedEventHandler 반환 PingReply 합니다. 속성을 PingReply 통해 액세스됩니다 Reply .

Status 이 아닌 Success경우 , Options 또는 Buffer 속성에서 RoundtripTime반환된 값을 사용하면 안 됩니다. 속성이 RoundtripTime 0을 반환하고, 속성이 Buffer 빈 배열을 반환하고, 속성이 Options 반환 null됩니다.

속성

Name Description
Address

ICMP(인터넷 제어 메시지 프로토콜) 에코 회신을 보내는 호스트의 주소를 가져옵니다.

Buffer

ICMP(인터넷 제어 메시지 프로토콜) 에코 회신 메시지에서 받은 데이터의 버퍼를 가져옵니다.

Options

회신을 ICMP(인터넷 제어 메시지 프로토콜) 에코 요청으로 전송하는 데 사용되는 옵션을 가져옵니다.

RoundtripTime

ICMP(인터넷 제어 메시지 프로토콜) 에코 요청을 보내고 해당 ICMP 에코 회신 메시지를 수신하는 데 걸린 시간(밀리초)을 가져옵니다.

Status

ICMP(인터넷 제어 메시지 프로토콜) 에코 요청을 보내고 해당 ICMP 에코 응답 메시지를 수신하려는 시도의 상태를 가져옵니다.

메서드

Name Description
Equals(Object)

지정된 개체가 현재 개체와 같은지 여부를 확인합니다.

(다음에서 상속됨 Object)
GetHashCode()

기본 해시 함수로 사용됩니다.

(다음에서 상속됨 Object)
GetType()

현재 인스턴스의 Type 가져옵니다.

(다음에서 상속됨 Object)
MemberwiseClone()

현재 Object단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
ToString()

현재 개체를 나타내는 문자열을 반환합니다.

(다음에서 상속됨 Object)

적용 대상