Click here to Skip to main content
15,888,113 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
public static void ComplexLocalPing ()
      {
          // Ping's the local machine.
          Ping pingSender = new Ping ();
          IPAddress address = IPAddress.Loopback;

          // Create a buffer of 32 bytes of data to be transmitted.
          string data = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
          byte[] buffer = Encoding.ASCII.GetBytes (data);

          // Wait 10 seconds for a reply.
          int timeout = 10000;

          // Set options for transmission:
          // The data can go through 64 gateways or routers
          // before it is destroyed, and the data packet
          // cannot be fragmented.
          PingOptions options = new PingOptions (64, true);
          PingReply reply = pingSender.Send (address, 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);
          }
          else
          {
              Console.WriteLine (reply.Status);
          }
      }


Suppose if i am sending data through this code to another machine, how user can see data send to him.
Posted

1 solution

There is no application I know of that will show you the data. An ICMP packet normally does not make it high enough up the network stack for that data to be shown. An application would have to be specifically written for the purpose and running on the target machine, with someone logged in at the console, for any data to be shown. The point behind PING is that is doesn't rely on anything running on the target machine besides the O/S and it's network stack in order to work. No application needs to be running and nobody needs to be logged in.

What you would ultimately be writing, based on your specifications, is a chat application. No need to use ICMP for that.
 
Share this answer
 
Comments
footballpardeep 7-Dec-13 12:41pm    
Earlier i used command "Ping 'someaddress' -t". When i see this code i.e sending data with code, after that it was my general query there must be any way to read that sent data.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900