title: How to Close TCP socket abruptly and reconnecting
body: <p>We use Linux 2.6.33 on device. A PC application will be used which connects to the device over TCP socket. There will be a maximum of 1 MB of data transferred upon request from application.</p>
  
  <p>Consider If the application is connected and working fine and in between the IP address of the device gets changed (which is possible with a command). Now the connection is broken abruptly at the application but on device it doesn't. But user expects to reconnect to the device with new IP address. In some cases the "send()' was halfway and may not have sent all data. Then this closing does not happen immediately. And hence user will not be able to reconnect until the socket is closed on device.</p>
  
  <p>I use "shutdown(sock, RDWR), close(sock)" sequence.
  The netstat output shows:</p>
  
  <pre><code>$ netstat -nt
  Proto Recv-Q Send-Q Local Address           Foreign Address         State
  tcp        0  29200 xx.xx.xx.xx:3000       xx.xx.xx.xx:50639       ESTABLISHED
  </code></pre>
  
  <p>As it shows the Send-Q is still not empty and so the connection is still in ESTABLISED state. This socket is closed after some time and I am not sure how much time it is. May be defined by socket implementation.</p>
  
  <p>How can i close this socket immediately so that a new connection over same TCP port is possible from PC application?</p>