no overload error

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Simon Porter

    no overload error

    Hi,

    I'm completely stuck with some example code I'm trying to use. The code
    is from
    Allows an application to determine whether a remote computer is accessible over the network.


    I would have thought to create a new 'PingExample' object the correct
    syntax would be,

    PingExample ping = new PingExample("si mon.heber.ltd") ;

    as the class is expecting a string as an argument.

    I get the following error though:

    No overload for method 'PingExample' takes '1' arguments

    Thanks for any help,

    Simon Porter

    using System;
    using System.Text;
    using System.Net;
    using System.Net.Netw orkInformation;
    using System.Componen tModel;
    using System.Threadin g;

    namespace Examples.System .Net.NetworkInf ormation.PingTe st
    {
    public class PingExample
    {
    public static void Main(string[] args)
    {
    if (args.Length == 0)
    throw new ArgumentExcepti on("Ping needs a host or IP Address.");

    string who = args[0];
    AutoResetEvent waiter = new AutoResetEvent( false);

    Ping pingSender = new Ping();

    // When the PingCompleted event is raised,
    // the PingCompletedCa llback method is called.
    pingSender.Ping Completed += new PingCompletedEv entHandler(Ping CompletedCallba ck);

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

    // Wait 12 seconds for a reply.
    int timeout = 12000;

    // 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);

    Console.WriteLi ne("Time to live: {0}", options.Ttl);
    Console.WriteLi ne("Don't fragment: {0}", options.DontFra gment);

    // Send the ping asynchronously.
    // Use the waiter as the user token.
    // When the callback completes, it can wake up this thread.
    pingSender.Send Async(who, timeout, buffer, options, waiter);

    // Prevent this example application from ending.
    // A real application should do something useful
    // when possible.
    waiter.WaitOne( );
    Console.WriteLi ne("Ping example completed.");
    }

    private static void PingCompletedCa llback(object sender, PingCompletedEv entArgs e)
    {
    // If the operation was canceled, display a message to the user.
    if (e.Cancelled)
    {
    Console.WriteLi ne("Ping canceled.");

    // Let the main thread resume.
    // UserToken is the AutoResetEvent object that the main thread
    // is waiting for.
    ((AutoResetEven t)e.UserState). Set();
    }

    // If an error occurred, display the exception to the user.
    if (e.Error != null)
    {
    Console.WriteLi ne("Ping failed:");
    Console.WriteLi ne(e.Error.ToSt ring());

    // Let the main thread resume.
    ((AutoResetEven t)e.UserState). Set();
    }

    PingReply reply = e.Reply;

    DisplayReply(re ply);

    // Let the main thread resume.
    ((AutoResetEven t)e.UserState). Set();
    }

    public static void DisplayReply(Pi ngReply reply)
    {
    if (reply == null)
    return;

    Console.WriteLi ne("ping status: {0}", reply.Status);
    if (reply.Status == IPStatus.Succes s)
    {
    Console.WriteLi ne("Address: {0}", reply.Address.T oString());
    Console.WriteLi ne("RoundTrip time: {0}", reply.Roundtrip Time);
    Console.WriteLi ne("Time to live: {0}", reply.Options.T tl);
    Console.WriteLi ne("Don't fragment: {0}", reply.Options.D ontFragment);
    Console.WriteLi ne("Buffer size: {0}", reply.Buffer.Le ngth);
    }
    }
    }
    }
  • Laura T

    #2
    Re: no overload error

    The PingExample class does not declare any constructor so it has only a
    default one, PingExample() w/o parameters.
    Thats why compiler is saying there is no overloaded constructor that accepts
    1 parameter.

    Still, the PingExample has only static (class level) methods so you don't
    need to create any instance.
    Just call the method main as "PingExample.Ma in(new string[] {
    "simon.heber.lt d" });"


    "Simon Porter" <simon@heber.co .ukha scritto nel messaggio
    news:OjbDNP2yGH A.4932@TK2MSFTN GP02.phx.gbl...
    Hi,
    >
    I'm completely stuck with some example code I'm trying to use. The code
    is from
    Allows an application to determine whether a remote computer is accessible over the network.

    >
    I would have thought to create a new 'PingExample' object the correct
    syntax would be,
    >
    PingExample ping = new PingExample("si mon.heber.ltd") ;
    >
    as the class is expecting a string as an argument.
    >
    I get the following error though:
    >
    No overload for method 'PingExample' takes '1' arguments
    >
    Thanks for any help,
    >
    Simon Porter
    >

    --------------------------------------------------------------------------------

    using System;
    using System.Text;
    using System.Net;
    using System.Net.Netw orkInformation;
    using System.Componen tModel;
    using System.Threadin g;
    >
    namespace Examples.System .Net.NetworkInf ormation.PingTe st
    {
    public class PingExample
    {
    public static void Main(string[] args)
    {
    if (args.Length == 0)
    throw new ArgumentExcepti on("Ping needs a host or IP
    Address.");
    >
    string who = args[0];
    AutoResetEvent waiter = new AutoResetEvent( false);
    >
    Ping pingSender = new Ping();
    >
    // When the PingCompleted event is raised,
    // the PingCompletedCa llback method is called.
    pingSender.Ping Completed += new
    PingCompletedEv entHandler(Ping CompletedCallba ck);
    >
    // Create a buffer of 32 bytes of data to be transmitted.
    string data = "aaaaaaaaaaaaaa aaaaaaaaaaaaaaa aaa";
    byte[] buffer = Encoding.ASCII. GetBytes(data);
    >
    // Wait 12 seconds for a reply.
    int timeout = 12000;
    >
    // 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);
    >
    Console.WriteLi ne("Time to live: {0}", options.Ttl);
    Console.WriteLi ne("Don't fragment: {0}", options.DontFra gment);
    >
    // Send the ping asynchronously.
    // Use the waiter as the user token.
    // When the callback completes, it can wake up this thread.
    pingSender.Send Async(who, timeout, buffer, options, waiter);
    >
    // Prevent this example application from ending.
    // A real application should do something useful
    // when possible.
    waiter.WaitOne( );
    Console.WriteLi ne("Ping example completed.");
    }
    >
    private static void PingCompletedCa llback(object sender,
    PingCompletedEv entArgs e)
    {
    // If the operation was canceled, display a message to the
    user.
    if (e.Cancelled)
    {
    Console.WriteLi ne("Ping canceled.");
    >
    // Let the main thread resume.
    // UserToken is the AutoResetEvent object that the main
    thread
    // is waiting for.
    ((AutoResetEven t)e.UserState). Set();
    }
    >
    // If an error occurred, display the exception to the user.
    if (e.Error != null)
    {
    Console.WriteLi ne("Ping failed:");
    Console.WriteLi ne(e.Error.ToSt ring());
    >
    // Let the main thread resume.
    ((AutoResetEven t)e.UserState). Set();
    }
    >
    PingReply reply = e.Reply;
    >
    DisplayReply(re ply);
    >
    // Let the main thread resume.
    ((AutoResetEven t)e.UserState). Set();
    }
    >
    public static void DisplayReply(Pi ngReply reply)
    {
    if (reply == null)
    return;
    >
    Console.WriteLi ne("ping status: {0}", reply.Status);
    if (reply.Status == IPStatus.Succes s)
    {
    Console.WriteLi ne("Address: {0}",
    reply.Address.T oString());
    Console.WriteLi ne("RoundTrip time: {0}",
    reply.Roundtrip Time);
    Console.WriteLi ne("Time to live: {0}", reply.Options.T tl);
    Console.WriteLi ne("Don't fragment: {0}",
    reply.Options.D ontFragment);
    Console.WriteLi ne("Buffer size: {0}", reply.Buffer.Le ngth);
    }
    }
    }
    }

    Comment

    Working...