Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. How to reconnect socket

How to reconnect socket

Scheduled Pinned Locked Moved C#
sysadmintutorial
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    engsrini
    wrote on last edited by
    #1

    Hi Im working on socket connection. client will send data to the server at some regular intervals. how the client can identify if the ethernet cable is unplugged (client has to show some message "cable disconnected". if cable is plugged again. It should detect it automatically has to continue the task again. Please give ur answers with some sample code/link Thanks and Regards, Srini

    M 1 Reply Last reply
    0
    • E engsrini

      Hi Im working on socket connection. client will send data to the server at some regular intervals. how the client can identify if the ethernet cable is unplugged (client has to show some message "cable disconnected". if cable is plugged again. It should detect it automatically has to continue the task again. Please give ur answers with some sample code/link Thanks and Regards, Srini

      M Offline
      M Offline
      mertkan65
      wrote on last edited by
      #2

      The recommended way to do this with V2.0 of the framework is to use the System.Net.NetworkInformation namespace.. This sample should get you started: public class NetInfoTest { public static void Main() { try { DumpIPAddresses(); NetworkChange.NetworkAvailabilityChanged += OnNetworkAvailabilityChanged; NetworkChange.NetworkAddressChanged += OnNetworkAddressChanged; Console.ReadLine(); } catch (Exception e) { Console.WriteLine(e); } finally { Console.ForegroundColor = ConsoleColor.Green; Console.BackgroundColor = ConsoleColor.Black; } } public static void OnNetworkAvailabilityChanged(object sender, NetworkAvailabilityEventArgs e) { if (e.IsAvailable) { Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("Network Available"); } else { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Network *NOT* Available"); } } public static void OnNetworkAddressChanged(object sender, EventArgs e) { Console.ForegroundColor = ConsoleColor.Red; Console.BackgroundColor = ConsoleColor.Yellow; Console.WriteLine("Address change event at {0}", DateTime.Now.ToString()); Console.ForegroundColor = ConsoleColor.Green; Console.BackgroundColor = ConsoleColor.Black; DumpIPAddresses(); } public static void DumpIPAddresses() { //1. Get All Network Interfaces NetworkInterface[] NetworkInterfaces = NetworkInterface.GetAllNetworkInterfaces(); //2. Loop over the interfaces foreach (NetworkInterface NI in NetworkInterfaces) { //3. Select Ethernet Interface if (NI.NetworkInterfaceType == NetworkInterfaceType.Ethernet) { Console.WriteLine(Environment.NewLine); Console.WriteLine(En

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups