title: Cannot assign requested address for bind the socket
body: <p>I checked my code but I don't know why the program can't bind the socket.
  I tried many ip and ports(even 127.0.0.1) but it still don't works...
  Here is the code I'm using :</p>
  
  <pre><code>//error message
  void error (const char *msg)
  {
      perror(msg);
      exit(1);
  }
  
  int main ()
  {
      int sock, cli_sock, portno;
      char buffer[1024];
      char response[18432];
  
      struct sockaddr_in serv_addr, cli_addr;
      socklen_t cli_len;
  
      //creating socket
      sock = socket(AF_INET, SOCK_STREAM, 0);
      if(sock &lt; 0)
          error("Error opening socket");
  
      bzero ((char *) &amp;serv_addr, sizeof(serv_addr));
  
      //giving port number
      portno = 50005;
  
      //giving ip address
      serv_addr.sin_family = AF_INET;
      serv_addr.sin_addr.s_addr = inet_addr("127.0.0.1");
      serv_addr.sin_port = htons(portno);
  
      //bind socket
      if(bind(sock, (struct sockaddr *) &amp;serv_addr, sizeof(serv_addr)) != 0)
          error("Binding failed.");
  
      //listen
      listen(sock, 5);
  
      cli_len = sizeof(cli_addr);
  
      //accept
      cli_sock = accept(sock, (struct sockaddr *) &amp;cli_addr, &amp;cli_len);
      if(cli_sock != 0)
          error("Error on accepting");
  }
  </code></pre>
  
  <p>(This is just the socket part of the server code and just for more info, my client version is for Windows and my server version is for Linux)</p>
  
  <p>This is my output when I run the program :</p>
  
  <p><code>Binding failed.: Cannot assign requested address</code></p>