• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# Ping类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中Ping的典型用法代码示例。如果您正苦于以下问题:C# Ping类的具体用法?C# Ping怎么用?C# Ping使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Ping类属于命名空间,在下文中一共展示了Ping类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: checkConnection

    // The state object is necessary for a TimerCallback.
    public void checkConnection(object stateObject)
    {
        Process p = new Process();
        Ping pingSender = new Ping ();
        p.StartInfo.FileName = "arp";
        p.StartInfo.Arguments = "-a";
        p.StartInfo.UseShellExecute = false;
        p.StartInfo.RedirectStandardOutput = true;

        string data = "a";
         byte[] buffer = Encoding.ASCII.GetBytes (data);

        for(int i = 0; i < 25 ; i++){
            pingSender.Send ("10.0.0."+i.ToString(),10,buffer);
        }

        p.Start();

        string output = p.StandardOutput.ReadToEnd();
        p.WaitForExit();

        string MAC = "xx-xx-xx-xx-xx-xx";
        if(output.Contains(MAC)){
            SerialPort port = new SerialPort("COM5", 9600);
            port.Open();
            port.Write("u");
            port.Close();
        }
        else{
            SerialPort port = new SerialPort("COM5", 9600);
            port.Open();
            port.Write("l");
            port.Close();
        }
    }
开发者ID:kurtvonehr,项目名称:ARP-Windows-Service,代码行数:36,代码来源:wifi_doorlock_service.cs


示例2: Any

		public object Any(Ping request)
		{
			return new PingResponse
	       	{
	       		Result = RedisNative.Ping()
	       	};
		}
开发者ID:JerryForNet,项目名称:RedisAdminUI,代码行数:7,代码来源:PingService.cs


示例3: SendPingAsync_InvalidArgs

        public async Task SendPingAsync_InvalidArgs()
        {
            IPAddress localIpAddress = await TestSettings.GetLocalIPAddress();
            Ping p = new Ping();

            // Null address
            Assert.Throws<ArgumentNullException>("address", () => { p.SendPingAsync((IPAddress)null); });
            Assert.Throws<ArgumentNullException>("hostNameOrAddress", () => { p.SendPingAsync((string)null); });

            // Invalid address
            Assert.Throws<ArgumentException>("address", () => { p.SendPingAsync(IPAddress.Any); });
            Assert.Throws<ArgumentException>("address", () => { p.SendPingAsync(IPAddress.IPv6Any); });

            // Negative timeout
            Assert.Throws<ArgumentOutOfRangeException>("timeout", () => { p.SendPingAsync(localIpAddress, -1); });
            Assert.Throws<ArgumentOutOfRangeException>("timeout", () => { p.SendPingAsync(TestSettings.LocalHost, -1); });

            // Null byte[]
            Assert.Throws<ArgumentNullException>("buffer", () => { p.SendPingAsync(localIpAddress, 0, null); });
            Assert.Throws<ArgumentNullException>("buffer", () => { p.SendPingAsync(TestSettings.LocalHost, 0, null); });

            // Too large byte[]
            Assert.Throws<ArgumentException>("buffer", () => { p.SendPingAsync(localIpAddress, 1, new byte[65501]); });
            Assert.Throws<ArgumentException>("buffer", () => { p.SendPingAsync(TestSettings.LocalHost, 1, new byte[65501]); });
        }
开发者ID:nbilling,项目名称:corefx,代码行数:25,代码来源:PingTest.cs


示例4: update

    //-------------------------------------------------------------------------
    public void update(float elapsed_tm)
    {
        if (!mStart) return;

        if (mPing != null && mPing.isDone)
        {
            PingTime = mPing.time;

            if (mPing != null)
            {
                mPing.DestroyPing();
                mPing = null;
                mPingTm = 5f;
            }
        }
        else if (mPing == null)
        {
            mPingTm -= elapsed_tm;
            if (mPingTm < 0f)
            {
                mPingTm = 5f;
                mPing = new Ping(mIp);
            }
        }
    }
开发者ID:CragonGame,项目名称:GameCloud.IM,代码行数:26,代码来源:EcPing.cs


示例5: Any

 public object Any(Ping request)
 {
     return new PingResponse()
     {
         Timestamp = DateTime.Now
     };
 }
开发者ID:csadevio,项目名称:dockstack,代码行数:7,代码来源:PingService.cs


示例6: Main

public static void Main(string [] args)
{
int pingsc = 0, pingf = 0;
int numb = Convert.ToInt32(args[1]);

Ping ping = new Ping();
PingOptions option = new PingOptions();
option.DontFragment = true;

string message = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaasdfasdfasdfasfasdfasdfasdfasdfasdfas";
byte [] val = Encoding.ASCII.GetBytes(message);
int timeout = 120;
for(int i = 0; i < numb; i++)
{
PingReply reply = ping.Send(args[0], timeout, val, option);
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("Buffer size {0}", reply.Buffer.Length); 
pingsc++;
}
else
{
Console.WriteLine("Ping failed");
pingf++;
}
}
Console.WriteLine("number of Success pings {0}", pingsc);
Console.WriteLine("Number of failed pings {0}", pingf);
}
开发者ID:EdiCarlos,项目名称:MyPractices,代码行数:32,代码来源:pingClass.cs


示例7: Main

 /// <summary>
 /// The main entry point for the application.
 /// </summary>
 private static void Main()
 {
     using (var game = new Ping())
     {
         game.Run();
     }
 }
开发者ID:kurtschindler,项目名称:ping,代码行数:10,代码来源:Program.cs


示例8: Main

    public static void Main(string[] args)
    {
        using (Ping ping = new Ping())
        {
            try
            {
                PingReply reply = ping.Send("127.0.0.1", 100);

                if (reply.Status == IPStatus.Success)
                {
                    Console.WriteLine("Success - IP Address:{0} Time:{1}ms",
                        reply.Address, reply.RoundtripTime);
                }
                else
                {
                    Console.WriteLine(reply.Status);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error ({0})", ex.InnerException.Message);
            }
        }

        Console.WriteLine("Press any key to continue...");
        Console.ReadKey();
    }
开发者ID:dbremner,项目名称:hycs,代码行数:27,代码来源:ping.cs


示例9: Update

 private void Update()
 {
     if ( this.hostDataIndex != -1 )
     {
         // Constantly create a new ping and send it off when the old one is returned
         if ( this.ping != null )
         {
             if ( this.ping.isDone )
             {
                 this.latency = this.ping.time;
                 this.ping = null;
                 this.UpdateGUI();
             }
         }
         else
         {
             HostData hostData = MenuNetworking.instance.GetHostData( this.hostDataIndex );
             if ( hostData == null )
             {
                 this.hostDataIndex = -1;
             }
             else
             {
                 this.ping = new Ping( string.Concat( hostData.ip ) );
             }
             //this.ping = new Ping( string.Concat( this.hostData.ip ) );
         }
     }
 }
开发者ID:marshl,项目名称:Leviathan2,代码行数:29,代码来源:MenuServerRow.cs


示例10: Update

    void Update()
    {
        if (Input.GetButtonDown("Server List"))
        {
            show = !show;
            if (show)
            {
                MasterServer.ClearHostList();
                MasterServer.RequestHostList("OmniDig");
            }
        }

        if (MasterServer.PollHostList().Length > 0)
        {
            servers = MasterServer.PollHostList();

            for(int i=0; i<servers.Length; i++)
            {
                if (serverPings[i] == null)
                {
                    serverPings[i] = new Ping(servers[i].ip[0]);
                }
            }
        }

        if (connect)
        {
            show = false;
            connect = false;
            OmniNetwork.Dedicated = false;
            Network.Connect(servers[connectSelection]);
        }
    }
开发者ID:jwatsn,项目名称:OmniDigUnity,代码行数:33,代码来源:OmniServerBrowser.cs


示例11: UpdateServer

    public void UpdateServer()
    {
        //get current server selection
        server = (int)slider.value;

        //web player ping
        ping = new Ping(IPs[server]);
    }
开发者ID:AndrewXA9,项目名称:LeagueOfLagDetection,代码行数:8,代码来源:Run.cs


示例12: Puck

        public Puck(Ping game, Vector2 position)
            : base(game)
        {
            _ping = game;

            _size = new Vector2(32f, 32f);
            _position = position;
            _velocity = new Vector2(5f);
        }
开发者ID:kurtschindler,项目名称:ping,代码行数:9,代码来源:Puck.cs


示例13: Can_serialize_IMessage_into_typed_Message_Ping

        public void Can_serialize_IMessage_into_typed_Message_Ping()
        {
            var dto = new Ping();
            IMessage iMsg = MessageFactory.Create(dto);
            var json = iMsg.ToJson();
            var typedMessage = json.FromJson<Message<Ping>>();

            Assert.That(typedMessage.GetBody(), Is.Not.Null);
        }
开发者ID:sami1971,项目名称:NServiceKit.Text,代码行数:9,代码来源:MessagingTests.cs


示例14: Paddle

        public Paddle(Ping game, Vector2 position)
            : base(game)
        {
            _ping = game;

            _size = new Vector2(24f, 88f);
            _position = position;
            _velocity = new Vector2(0f);
        }
开发者ID:TimGThomas,项目名称:ping,代码行数:9,代码来源:Paddle.cs


示例15: when_serializing_ping_then_can_roundtrip

        public void when_serializing_ping_then_can_roundtrip()
        {
            var message = new Ping();
            var bytes = MessageChannel.Convert(message);

            var deserialized = MessageChannel.Convert(bytes) as Ping;

            Assert.NotNull(deserialized);
        }
开发者ID:kzu,项目名称:Sensorium,代码行数:9,代码来源:MessageChannelFixture.cs


示例16: Start

 public MyHostData Start(HostData hd)
 {
     this.hd = hd;
     foreach (var ip in hd.ip)
     {
         var p = new Ping(ip);
         pp.Add(p);
     }
     return this;
 }
开发者ID:ConnectDeveloper01,项目名称:dorumon,代码行数:10,代码来源:Menu.cs


示例17: stop

    //-------------------------------------------------------------------------
    public void stop()
    {
        mStart = false;

        if (mPing != null)
        {
            mPing.DestroyPing();
            mPing = null;
        }
    }
开发者ID:CragonGame,项目名称:GameCloud.IM,代码行数:11,代码来源:EcPing.cs


示例18: ascx_Task_Ping

 public ascx_Task_Ping()
 {
     TaskType = "Ping";
     TaskName = "...";
     TaskFunction = () =>
     {
         var ping = new Ping();
         return ping.ping(TaskName);
     };
 }
开发者ID:CallMeSteve,项目名称:FluentSharp,代码行数:10,代码来源:ascx_Task_Ping.cs


示例19: RequestResponse

        public void RequestResponse()
        {
            var query = new Ping();

            var mediator = ObjectFactory.GetInstance<IMediator>();

            var pong = mediator.Request(query);

            Assert.That(pong.Data, Is.EqualTo("PONG!"));
            Assert.That(pong.HasException(), Is.False);
        }
开发者ID:rossipedia,项目名称:ShortBus,代码行数:11,代码来源:BasicExample.cs


示例20: OnPlayerConnected

    void OnPlayerConnected( NetworkPlayer player )
    {
        //Store networkplayers in the 3 connections data on connect.
        network_players[ npindex ] = player;
        //ping them.
        pings[ npindex ] = new Ping( network_players[ npindex ].ipAddress );
        //increment.
        npindex++;

        //networkView.RPC ("functionname", NetworkPlayer <Target>, params);
    }
开发者ID:EmergentRealityLab,项目名称:BasicCAVETest,代码行数:11,代码来源:SynchingViaPing.cs



注:本文中的Ping类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# PingMessage类代码示例发布时间:2022-05-24
下一篇:
C# PinState类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap