Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

Ping.Send Method (String, Int32)

Attempts to send an Internet Control Message Protocol (ICMP) echo message to the specified computer, and receive a corresponding ICMP echo reply message from that computer. This method allows you to specify a time-out value for the operation.

Namespace: System.Net.NetworkInformation
Assembly: System (in system.dll)

public PingReply Send (
	string hostNameOrAddress,
	int timeout
)
public PingReply Send (
	String hostNameOrAddress, 
	int timeout
)
public function Send (
	hostNameOrAddress : String, 
	timeout : int
) : PingReply
Not applicable.

Parameters

hostNameOrAddress

A String that identifies the computer that is the destination for the ICMP echo message. The value specified for this parameter can be a host name or a string representation of an IP address.

timeout

An Int32 value that specifies the maximum number of milliseconds (after sending the echo message) to wait for the ICMP echo reply message.

Return Value

A PingReply object that provides information about the ICMP echo reply message if one was received, or provides the reason for the failure if no message was received.

Exception typeCondition

ArgumentNullException

hostNameOrAddress is a null reference (Nothing in Visual Basic) or is an empty string ("").

ArgumentOutOfRangeException

timeout is less than zero.

InvalidOperationException

A call to SendAsync is in progress.

SocketException

hostNameOrAddress could not be resolved to a valid IP address.

ObjectDisposedException

This object has been disposed.

If the ICMP echo reply message is not received within the time specified in the timeout parameter, the ICMP echo fails, and the Status property is set to TimedOut.

NoteNote:

When specifying very small numbers for timeout, the Ping reply can be received even if timeout milliseconds have elapsed.

This overload uses default settings for packet fragmentation and packet forwarding. The packet that contains the ICMP echo message can be fragmented in transit if the total packet size exceeds the maximum packet size that can be transmitted by one of the routing nodes between the local and remote computers. To prevent fragmentation, use one of the Send methods that takes an options parameter, and set the DontFragment property to true. When DontFragment is true and the total packet size exceeds the maximum packet size that can be transmitted by one of the routing nodes between the local and remote computers, the ICMP echo request fails. When this happens, the Status is set to PacketTooBig. The packet or packet fragments (if fragmented) can be forwarded by routing nodes 128 times before being discarded. To change this setting, use a Send overload that takes an options parameter, and set the Ttl property to the desired value. If the packet does not reach its destination after being forwarded the specified number of times, the packet is discarded and the ICMP echo request fails. When this happens, the Status is set to TtlExpired.

For an example that demonstrates calling a Send method, see the Ping class overview.

Windows 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

Show:
© 2014 Microsoft