public void SendNextPingRequest(Logging.IBasicLogger logger) { if (ping == null) { ping = new System.Net.NetworkInformation.Ping(); ping.PingCompleted += ping_PingCompleted; } lock (mutex) { pingCompleteEventArgs = null; pingToReplyElapsedTime = TimeSpan.Zero; currentUserToken = Token.SetToNow(); try { ping.SendAsync(IPAddress, responseTimeLimitInMSec, extraData, currentUserToken); } catch (System.Exception ex) { logger.Trace.Emit("{0} (SendAsync) generated unexpected exception: {1}", CurrentMethodName, ex.ToString(ExceptionFormat.TypeAndMessage)); } } }
private void PingUpdateSystem(string in_region, string in_target) { System.Net.NetworkInformation.Ping pinger = new System.Net.NetworkInformation.Ping(); try { pinger.PingCompleted += (o, e) => { if (e.Error == null && e.Reply.Status == System.Net.NetworkInformation.IPStatus.Success) { handlePingTimeResponse(e.Reply.RoundtripTime, in_region); } }; pinger.SendAsync(in_target, null); } catch (System.Net.NetworkInformation.PingException) { // Discard PingExceptions and return false; } finally { if (pinger != null) { pinger.Dispose(); } } }
//public SocketClient(String serverIp, String serverPorts) //{ // String newServerIp = ""; // AddressFamily newAddressFamily = AddressFamily.InterNetwork; // getIPType(serverIp, serverPorts, out newServerIp, out newAddressFamily); // if (!string.IsNullOrEmpty(newServerIp)) { serverIp = newServerIp; } // socketClient = new Socket(newAddressFamily, SocketType.Stream, ProtocolType.Tcp); // ClientLog.Instance.Log("Socket AddressFamily :" + newAddressFamily.ToString() + "ServerIp:" + serverIp); //} public void Ping(string ip) { new System.Threading.Thread(() => { try { System.Net.NetworkInformation.Ping p = new System.Net.NetworkInformation.Ping(); string data = "Hello!"; byte[] buffer = System.Text.Encoding.ASCII.GetBytes(data); int timeout = 1000; // Timeout 时间,单位:毫秒 p.PingCompleted += new System.Net.NetworkInformation.PingCompletedEventHandler((object sender, System.Net.NetworkInformation.PingCompletedEventArgs e) => { try { if (e.Error != null) { ByteBuffer buffer2 = new ByteBuffer(); buffer2.WriteString(string.Format("Ping:{0},Error:{1}", ip, e.Error.Message)); AddEvent(Protocal.Ping, new ByteBuffer(buffer2.ToBytes())); } System.Net.NetworkInformation.PingReply reply = e.Reply; if (reply != null && reply.Status == System.Net.NetworkInformation.IPStatus.Success) { System.Text.StringBuilder sb = new System.Text.StringBuilder(); sb.AppendFormat("AcceptHost:{0}\n", reply.Address.ToString()); sb.AppendFormat("RoundTime:{0}\n", reply.RoundtripTime); sb.AppendFormat("TTL:{0}", reply.Options.Ttl); sb.AppendFormat("DontFragment:{0}", reply.Options.DontFragment); sb.AppendFormat("Length:{0}", reply.Buffer.Length); ByteBuffer buffer2 = new ByteBuffer(); buffer2.WriteString(sb.ToString()); AddEvent(Protocal.Ping, new ByteBuffer(buffer2.ToBytes())); } else { ByteBuffer buffer2 = new ByteBuffer(); buffer2.WriteString(string.Format("Ping:{0},Cannot Reachable", ip)); AddEvent(Protocal.Ping, new ByteBuffer(buffer2.ToBytes())); } } catch (Exception ex) { ByteBuffer buffer2 = new ByteBuffer(); buffer2.WriteString(string.Format("Ping:{0},Error:{1}", ip, ex.Message)); AddEvent(Protocal.Ping, new ByteBuffer(buffer2.ToBytes())); } }); p.SendAsync(ip, timeout, buffer, null); } catch (Exception ex) { ByteBuffer buffer2 = new ByteBuffer(); buffer2.WriteString(string.Format("Ping:{0},Error:{1}", ip, ex.Message)); AddEvent(Protocal.Ping, new ByteBuffer(buffer2.ToBytes())); } }).Start(); }
private void GetPingHost(string host, int timeOut) { AutoResetEvent waiter = new AutoResetEvent(false); System.Net.NetworkInformation.PingOptions options = new System.Net.NetworkInformation.PingOptions(64, true); string data = "aaaaa"; byte[] buffer = System.Text.Encoding.ASCII.GetBytes(data); System.Net.NetworkInformation.Ping pingCheck = new System.Net.NetworkInformation.Ping(); pingCheck.PingCompleted += new System.Net.NetworkInformation.PingCompletedEventHandler(PingCompletedCallback); pingCheck.SendAsync(host, timeOut, buffer, options, waiter); }
/// <summary> /// Pings the clients. /// </summary> /// <param name="state">The state.</param> internal void PingClients(object state) { if (Clients.Count > 0 && !ShuttingDown) { byte[] buffer = Encoding.ASCII.GetBytes(pingData); foreach (KeyValuePair <int, ClientConnection> cc in Clients) { pingSender.SendAsync(((IPEndPoint)cc.Value.ThisClient.Client.RemoteEndPoint).Address, TCPTimeout, buffer, cc.Value.ThisID); } } }
private void LookupPingCheck() { System.Net.NetworkInformation.Ping pingSender = new System.Net.NetworkInformation.Ping(); // Create an event handler for ping complete pingSender.PingCompleted += new System.Net.NetworkInformation.PingCompletedEventHandler(Ping_Complete); Network.UpdateLog("general", "Checking if online..."); // Send the ping asynchronously string site = TestSites[Core.RndGen.Next(TestSites.Length)]; pingSender.SendAsync(site, 5000, null); }
} // Main // http://pberblog.com/post/2009/07/21/Multithreaded-ping-sweeping-in-VBnet.aspx // http://www.cyberciti.biz/faq/how-can-ipv6-address-used-with-webbrowser/#comments // http://www.kloth.net/services/iplocate.php // http://bytes.com/topic/php/answers/829679-convert-ipv4-ipv6 // http://stackoverflow.com/questions/1434342/ping-class-sendasync-help public void SendPingAsync(System.Net.IPAddress sniIPaddress) { int iTimeout = 5000; System.Net.NetworkInformation.Ping myPing = new System.Net.NetworkInformation.Ping(); System.Net.NetworkInformation.PingOptions parmPing = new System.Net.NetworkInformation.PingOptions(); System.Threading.AutoResetEvent waiter = new System.Threading.AutoResetEvent(false); myPing.PingCompleted += new System.Net.NetworkInformation.PingCompletedEventHandler(AsyncPingCompleted); string data = "ABC"; byte[] dataBuffer = Encoding.ASCII.GetBytes(data); parmPing.DontFragment = true; parmPing.Ttl = 32; myPing.SendAsync(sniIPaddress, iTimeout, dataBuffer, parmPing, waiter); //waiter.WaitOne(); }
private void Button_Click(object sender, RoutedEventArgs e) { lvInformation.ItemsSource = DomainComputers; List <string> Computers = new List <string>(); for (int i = 1; i < 255; i++) { Computers.Add("192.168.9." + i.ToString()); } foreach (var comp in Computers) { System.Net.NetworkInformation.Ping objping = new System.Net.NetworkInformation.Ping(); objping.PingCompleted += new PingCompletedEventHandler(objping_PingCompleted); objping.SendAsync(comp, comp); } }
private void PingRemoteComputer() { try { btnPing.Image = Properties.Resources.Orange16x16; toolTip1.SetToolTip(btnPing, _localization.GetLocalizedString("Testing")); if (!String.IsNullOrEmpty(txtBxComputerName.Text)) { using (var ping = new System.Net.NetworkInformation.Ping()) { ping.PingCompleted += Ping_PingCompleted; ping.SendAsync(txtBxComputerName.Text, null); } } } catch (Exception ex) { btnPing.Image = Properties.Resources.Red16x16; toolTip1.SetToolTip(btnPing, _localization.GetLocalizedString("CantPing")); } }
/// <summary> /// 获取局域网内所有IP地址和对应的Mac地址、主机名 /// </summary> /// <param name="err"></param> /// <returns></returns> public void GetLoaclAllAddress(ref string err) { try { //获取本地机器名 string _myHostName = System.Net.Dns.GetHostName(); //获取本机IP string _myHostIP = System.Net.Dns.GetHostEntry(_myHostName).AddressList[0].ToString(); //截取IP网段 string ipDuan = _myHostIP.Remove(_myHostIP.LastIndexOf('.')); //枚举网段计算机 for (int i = 1; i <= 255; i++) { System.Net.NetworkInformation.Ping myPing = new System.Net.NetworkInformation.Ping(); myPing.PingCompleted += new System.Net.NetworkInformation.PingCompletedEventHandler(Ping_PingCompleted); string pingIP = ipDuan + "." + i.ToString(); myPing.SendAsync(pingIP, 1000, null); } } catch (Exception ex) { throw ex; } }
public override void Init() { Application.Log("Program.Init"); ClientXmlFormatterBinder.Instance.BindClientTypes(); LoadControls(); SignalEvent(ProgramEventType.ProgramStarted); #if DEBUG RedGate.Profiler.UserEvents.ProfilerEvent.SignalEvent("Init start"); #endif Content.ContentPath = Program.DataPath; Game.Map.GameEntity.ContentPool = Content; Bitmap b = new Bitmap(Common.FileSystem.Instance.OpenRead(Content.ContentPath + "/Interface/Cursors/MenuCursor1.png")); Graphics.Cursors.Arrow = NeutralCursor = Cursor = new System.Windows.Forms.Cursor(b.GetHicon()); Graphics.Interface.InterfaceScene.DefaultFont = Fonts.Default; if (Settings.DeveloperMainMenu) { MainMenuDefault = MainMenuType.DeveloperMainMenu; ProfileMenuDefault = ProfileMenuType.DeveloperMainMenu; } else if (Settings.ChallengeMapMode) { MainMenuDefault = MainMenuType.ChallengeMap; ProfileMenuDefault = ProfileMenuType.ChallengeMap; } else { MainMenuDefault = MainMenuType.MainMenu; ProfileMenuDefault = ProfileMenuType.ProfileMenu; } if (Settings.DisplaySettingsForm) { OpenDeveloperSettings(); } //Graphics.Content.DefaultModels.Load(Content, Device9); InterfaceScene = new Graphics.Interface.InterfaceScene(); InterfaceScene.View = this; ((Graphics.Interface.Control)InterfaceScene.Root).Size = new Vector2(Program.Settings.GraphicsDeviceSettings.Resolution.Width, Program.Settings.GraphicsDeviceSettings.Resolution.Height); InterfaceScene.Add(Interface); InterfaceScene.Add(AchievementsContainer); InterfaceScene.Add(PopupContainer); InterfaceScene.Add(FeedackOnlineControl); if (!String.IsNullOrEmpty(Program.Settings.BetaSurveyLink)) { var u = new Uri(Program.Settings.BetaSurveyLink); var s = u.ToString(); if (!u.IsFile) { Button survey = new Button { Text = "Beta survey", Anchor = Orientation.BottomRight, Position = new Vector2(10, 50), Size = new Vector2(110, 30) }; survey.Click += new EventHandler((o, e) => { Util.StartBrowser(s); }); InterfaceScene.Add(survey); } } InterfaceScene.Add(Tooltip); InterfaceScene.Add(MouseCursor); InputHandler = InterfaceManager = new Graphics.Interface.InterfaceManager { Scene = InterfaceScene }; // Adjust the main char skin mesh; remove the dummy weapons var mainCharSkinMesh = Program.Instance.Content.Acquire<SkinnedMesh>( new SkinnedMeshFromFile("Models/Units/MainCharacter1.x")); mainCharSkinMesh.RemoveMeshContainerByFrameName("sword1"); mainCharSkinMesh.RemoveMeshContainerByFrameName("sword2"); mainCharSkinMesh.RemoveMeshContainerByFrameName("rifle"); try { SoundManager = new Client.Sound.SoundManager(Settings.SoundSettings.AudioDevice, Settings.SoundSettings.Engine, Settings.SoundSettings.MinMaxDistance.X, Settings.SoundSettings.MinMaxDistance.Y, Common.FileSystem.Instance.OpenRead); SoundManager.Settings = Settings.SoundSettings; SoundManager.ContentPath = Program.DataPath + "/Sound/"; SoundManager.Muted = Settings.SoundSettings.Muted; SoundManager.LoadSounds(!Settings.ChallengeMapMode); if (SoundLoaded != null) SoundLoaded(SoundManager, null); SoundManager.Volume = Settings.SoundSettings.MasterVolume; SoundManager.GetSoundGroup(Client.Sound.SoundGroups.Ambient).Volume = Settings.SoundSettings.AmbientVolume; SoundManager.GetSoundGroup(Client.Sound.SoundGroups.Music).Volume = Settings.SoundSettings.MusicVolume; SoundManager.GetSoundGroup(Client.Sound.SoundGroups.SoundEffects).Volume = Settings.SoundSettings.SoundVolume; SoundManager.GetSoundGroup(Client.Sound.SoundGroups.Interface).Volume = Settings.SoundSettings.SoundVolume; } catch (Client.Sound.SoundManagerException ex) { SendSoundFailureLog(ex); SoundManager = new Client.Sound.DummySoundManager(); System.Windows.Forms.MessageBox.Show( Locale.Resource.ErrorFailInitSoundDevice, Locale.Resource.ErrorFailInitSoundDeviceTitle, System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error); } //StateManager = new DummyDevice9StateManager(Device9); StateManager = new Device9StateManager(Device9); InterfaceRenderer = new Graphics.Interface.InterfaceRenderer9(Device9) { Scene = InterfaceScene, StateManager = StateManager, #if PROFILE_INTERFACERENDERER PeekStart = () => ClientProfilers.IRPeek.Start(), PeekEnd = () => ClientProfilers.IRPeek.Stop() #endif }; InterfaceRenderer.Initialize(this); BoundingVolumesRenderer = new BoundingVolumesRenderer { StateManager = Program.Instance.StateManager, View = Program.Instance }; #if BETA_RELEASE Client.Settings defaultSettings = new Settings(); ValidateSettings("", defaultSettings, Settings); #endif if (Settings.QuickStartMap != null && Settings.QuickStartMap != "" && Common.FileSystem.Instance.FileExists("Maps/" + Settings.QuickStartMap + ".map")) { LoadNewState(new Game.Game("Maps/" + Settings.QuickStartMap)); return; } UpdateFeedbackOnlineControl(); System.Net.NetworkInformation.Ping p = new System.Net.NetworkInformation.Ping(); p.PingCompleted += new System.Net.NetworkInformation.PingCompletedEventHandler((o, e) => { FeedbackOnline = e.Reply != null && e.Reply.Status == System.Net.NetworkInformation.IPStatus.Success; UpdateFeedbackOnlineControl(); }); var statsUri = new Uri(Settings.StatisticsURI); p.SendAsync(statsUri.DnsSafeHost, null); if (Settings.DeveloperMainMenu) InitDeveloperMenu(); else if (Settings.ChallengeMapMode) InitChallengeMapMode(); else InitFullGame(); EnterMainMenuState(false); if(WindowMode == WindowMode.Fullscreen) MouseCursor.BringToFront(); AskAboutUpdate(); if (!String.IsNullOrEmpty(Program.Settings.StartupMessage)) { Dialog.Show(Program.Settings.StartupMessageTitle ?? "", Program.Settings.StartupMessage); } fixedFrameStepSW.Start(); Application.Log("Program.Init completed"); #if DEBUG RedGate.Profiler.UserEvents.ProfilerEvent.SignalEvent("Init end"); #endif }