title: Unreachable IP Socket Close Time in Windows OS
body: <p>These codes provide send data via User Datagram Protocol. There are two codes at below. When I use the first code for unreachable Ip address I got the three-second delay. </p>
  
  <hr>
  
  <p><strong><em>Please Look New Results Title</em></strong></p>
  
  <hr>
  
  <p><strong><em>JUST OPEN NEW C# CONSOLE APP AND PASTE THESE CODES IN IT. (FIRST CODE)</em></strong></p>
  
  <pre><code>using System;
  using System.Net;
  using System.Net.Sockets;
  
  namespace Test
  {
      class Program
      {
          static void Main(string[] args)
          {
              byte[] data = { 1, 20, 60, 44, 244 };
              while (true)
              {
                  Console.WriteLine(DateTime.Now.ToString("h:mm:ss tt"));
                  try
                  {
                      using (var client = new UdpClient())
                      {
                          // Please check IP Address, It must be unreachable...
                         // IPEndPoint ep = new IPEndPoint(IPAddress.Parse("192.168.1.141"), 55600);
                        //  client.Connect(ep);
                          client.Send(data, data.Length, "192.168.1.141" , 55600);
                      }
                      Console.WriteLine(DateTime.Now.ToString("h:mm:ss tt"));
                      Console.WriteLine("    ");
                  }
                  catch (Exception ex)
                  {
                      Console.WriteLine(ex.ToString());
                  }
              }
          }
      }
  }
  </code></pre>
  
  <blockquote>
    <p><strong>Test 1(with using)</strong>: Reachable IP<br>
    <strong>Test 2(with using)</strong>: Unreachable IP<br>
    <strong>Output:</strong><br>
    <strong><em>Test1</em></strong>    label1 ---> h:mm:ss         label2 ---> h:mm:ss (Same Time)<br>
    <strong><em>Test2</em></strong>      label1 ---> h:mm:ss        label2 ---> h:mm:ss +3 second<br>
    <strong>(No exception)</strong></p>
    
    <p><strong>WireShark Results:</strong><br>
    <strong>Test 1(with using)</strong> : Reachable Ip --> Data is caught, seen.<br>
    <strong>Test 2(with using)</strong> : Unreachable IP-> No data.</p>
    
    <p>When I use without "using" blocks, I didn't get the three-second
    delay.</p>
  </blockquote>
  
  <p><strong><em>JUST OPEN NEW C# CONSOLE APP AND PASTE THESE CODES IN IT. (SECOND CODE)</em></strong></p>
  
  <pre><code>using System;
  using System.Net;
  using System.Net.Sockets;
  
  namespace Test
  {
      class Program
      {
          static void Main(string[] args)
          {
              byte[] data = { 1, 20, 60, 44, 244 };
              while (true)
              {
                  Console.WriteLine(DateTime.Now.ToString("h:mm:ss tt"));
                  try
                  {
                      var client = new UdpClient();
                      //Please check IP address, It must be unreachable...
                     // IPEndPoint ep = new IPEndPoint(IPAddress.Parse("192.168.1.41"), 5600);
                     // client.Connect(ep);
                      client.Send(data, data.Length, "192.168.1.141", 55600);
  
                      Console.WriteLine(DateTime.Now.ToString("h:mm:ss tt"));
                  }
                  catch (Exception xe)
                  {
                      Console.WriteLine(xe.ToString());
                  }
                  Console.WriteLine("   ");
                  System.Threading.Thread.Sleep(1000);
              }
          }
      }
  }
  </code></pre>
  
  <blockquote>
    <p><strong>Test 1(without using)</strong> : Reachable Ip<br>
    <strong>Test 2(without using)</strong> : Unreachable Ip</p>
    
    <p><strong>Output:</strong><br>
    <strong><em>Test1</em></strong>     label1 ---> h:mm:ss (Same Time)      label2 ---> h:mm:ss (Same Time)<br>
    <strong><em>Test2</em></strong>     label1 ---> h:mm:ss (Same Time)      label2 ---> h:mm:ss (Same Time)<br>
    <strong>(No exception)</strong></p>
    
    <p><strong>WireShark Results:</strong><br>
    <strong>Test 1(without using)</strong> : Reachable Ip --> Data is caught, seen.<br>
    <strong>Test 2(without using)</strong> : Unreachable IP-> No data.</p>
  </blockquote>
  
  <p><strong>What is the mean of that three-second delay?</strong><br>
  I am not sure but I think I have to use "using" blocks because if I didn't use the blocks memory usage will increase very high stage. 
  What is the difference between both codes? Which one is more reliable? Is there any better way? I don't want the three-second delay.</p>
  
  <p><strong>How to decrease three-second delay to zero?</strong></p>
  
  <p>Thanks in advance...</p>
  
  <hr>
  
  <p><strong><em>NEW RESULTS</em></strong></p>
  
  <blockquote>
    <p>I have tried socket Close/Dispose for unreachable IP with Python Programming
    Language in Windows OS.  I got same result namely three-second delay for unreachable
    IP. But when I try same Python code within Ubuntu 15.10, I didn't get
    the three-second delay.</p>
  </blockquote>
  
  <pre><code>import socket
  import datetime
  
  IPADDR = '192.168.1.141'
  PORTNUM = 5600
  PACKETDATA = "f1a525da11f6".encode()
  
  while(True):
      s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, 0)
      s.connect((IPADDR, PORTNUM))
      s.send(PACKETDATA)
      print(datetime.datetime.now())
      s.close()
  </code></pre>