title: php Socket Socket_bind() unable to bind address [10013]
body: <p>My situation:</p>
  
  <ul>
  <li>I have a program which send on a port (4448) a lot of data from some machines.</li>
  <li>I can retrieve that datas from a telnet connection.</li>
  </ul>
  
  <p>telnet steps:</p>
  
  <ul>
  <li>launch as cmd as ADMIN</li>
  <li>write telnet and send</li>
  <li>write "open localhost 4448" and send</li>
  <li>write "GET xx,yy"</li>
  <li>after this i just read on screen info in live</li>
  </ul>
  
  <p>xx and yy are numbers which identifies the machine</p>
  
  <p>Now lets go on php side I have my index.php but when I execute socket bind it gives me back an error (reported under the code) and about the code, this come from: <a href="http://php.net/manual/en/sockets.examples.php" rel="nofollow noreferrer">http://php.net/manual/en/sockets.examples.php</a> and its the first example, i read and tried this solution also <a href="https://www.codeproject.com/Tips/418814/Socket-Programming-in-PHP" rel="nofollow noreferrer">https://www.codeproject.com/Tips/418814/Socket-Programming-in-PHP</a> which use 2 php files, in both cases i get the same error...</p>
  
  <pre><code>&lt;?php
  error_reporting(E_ALL);
  
  /* Allow the script to hang around waiting for connections. */
  set_time_limit(0);
  
  /* Turn on implicit output flushing so we see what we're getting
   * as it comes in. */
  ob_implicit_flush();
  
  $address = 'localhost';
  $port = 4448;
  
  if (($sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP)) === false) {
      echo "socket_create() failed: reason: " . socket_strerror(socket_last_error()) . "\n";
  }
  
  if (socket_bind($sock, $address, $port) === false) {
      echo "socket_bind() failed: reason: " . socket_strerror(socket_last_error($sock)) . "\n";
  }
  
  if (socket_listen($sock, 5) === false) {
      echo "socket_listen() failed: reason: " . socket_strerror(socket_last_error($sock)) . "\n";
  }
  
  do {
      if (($msgsock = socket_accept($sock)) === false) {
          echo "socket_accept() failed: reason: " . socket_strerror(socket_last_error($sock)) . "\n";
          break;
      }
      /* Send instructions. */
      $msg = "GET xx,yy";
      socket_write($msgsock, $msg, strlen($msg));
  
      do {
          if (false === ($buf = socket_read($msgsock, 2048, PHP_NORMAL_READ))) {
              echo "socket_read() failed: reason: " . socket_strerror(socket_last_error($msgsock)) . "\n";
              break 2;
          }
          if (!$buf = trim($buf)) {
              continue;
          }
          if ($buf == 'quit') {
              break;
          }
          if ($buf == 'shutdown') {
              socket_close($msgsock);
              break 2;
          }
          $talkback = "PHP: You said '$buf'.\n";
          socket_write($msgsock, $talkback, strlen($talkback));
          echo "$buf\n";
      } while (true);
      socket_close($msgsock);
  } while (true);
  
  socket_close($sock);
  ?&gt;
  </code></pre>
  
  <p>and this is the error i get:</p>
  
  <blockquote>
    <p>Warning: socket_bind(): unable to bind address [10013]: An attempt was
    made to access a socket in a way forbidden by its access permissions</p>
  </blockquote>
  
  <p>I have already looked for administrator privileges and I think its all right.</p>
  
  <p>Extra info: I am working with PHP 7, my web server is Apache in Xampp package.</p>