title: why it can be "bad file number" when i write to socket
body: <p>I have a problem with sending message to server socket from client.
  write function returns error - <strong>bad file number</strong>. It means that I haven't permission to write to this socket.
  But from another client I can write to this socket, and do it successfully.
  Most interesting, that when another client connected to server my(problem) client can send message too.</p>
  
  <p>the code of my client:</p>
  
  <pre class="lang-c prettyprint-override"><code>SOCKET OnceCommand;
  struct sockaddr_in SAddress4;
  
  struct autoC
  {
    char buf[4];
    short fromx;
    short fromy;
    short tox;
    short toy;
    char step;
    char cycle;
  };
  union autocomm{
    char byte[14];
    struct autoC command;
  } Command1, Command2;
  
  memset(&amp;SAddress4,0,sizeof(SAddress4));
  SAddress4.sin_family = AF_INET;
  SAddress4.sin_port = htons(444);
  SAddress4.sin_addr.s_addr = inet_addr(RobotsIP[Robot1]);
  memset(&amp;(SAddress4.sin_zero),0,8);
  
  if((OnceCommand = socket(AF_INET,SOCK_STREAM,0))!=SOCKET_ERROR)
  {
    Err(OnceCommand);
    if(conn = connect(OnceCommand,(struct sockaddr *)&amp;SAddress4,sizeof(struct sockaddr))!=SOCKET_ERROR)
    {
      rc = write(OnceCommand,(char*)Command1.byte,sizeof(Command1.byte));
      if(rc &lt; 0)
      {
        perror("Client-write() error");
        rc = getsockopt(OnceCommand, SOL_SOCKET, SO_ERROR, &amp;temp, &amp;length);
        if(rc == 0)
        {
          Err(OnceCommand);
          perror("SO_ERROR was");
        }
        closesocket(OnceCommand);
      }
      else
      {
        adv_printf("Client-write() is OK\n");
        adv_printf("String successfully sent lol!\n");
      }
      shutdown(OnceCommand,2);
      closesocket(OnceCommand);
    }
  }
  </code></pre>
  
  <p>in SO_ERROR was "bad file number"</p>
  
  <p>I'm using sockets lib in ADAM-5510 microcontroller based with ROM-DOS.</p>
  
  <p>I tried to solve this problem by using NONBLOCKing sockets, but select returns only read ready flag.</p>