title: How to reduce waiting time for tcp connection?
body: <p>I use TCP connection to send different messages between two applications. And when you try to send message to another app and this app is not launched, app throwing an exception. Sometimes it takes 10 seconds before throw an exception. How can i reduce this time to 2-3 seconds ?</p>
  
  <p>This is code for sender:</p>
  
  <pre><code>TcpClient client = new TcpClient();
  NetworkStream ns;
  client.Connect(new IPEndPoint(IPAddress.Parse(ip_address), port));
  string str;
  StreamWriter sw = new StreamWriter(client.GetStream());
  sw.AutoFlush = true;
  sw.WriteLine(str);
  client.Close();
  </code></pre>
  
  <p>And this is code for reciever:</p>
  
  <pre><code>TcpListener listner = new TcpListener(new IPEndPoint(IPAddress.Parse(local_ipAddress), port));
  listner.Start();
  TcpClient client = listner.AcceptTcpClient();
  StreamReader sr = new StreamReader(client.GetStream());
  string str = sr.ReadLine();
  client.Close();
  </code></pre>