title: Test to see if a socket is open in linux
body: <p>I have a linux server program that waits for incoming connections from a client and depending on what command you send it performs a different connection. Here is the pseudo-code</p>
  
  <pre><code>setup_socket();
  
  while(1)
  {
     listen();
     newfile_descriptor = accept();
     int command
     read(newfile_descriptor,&amp;command,sizeof(int));
     switch(command)
     {
        ...
     }
  }
  </code></pre>
  
  <p>But when I want to send more than one command with the same client it listens forever (since a new connection is not being made). Is there a way to check if there is already connection before listening to a new one?</p>