title: PHP socket_bind(): unable to bind address [10013]
body: <p>I'm trying to make an udp socket connection to a specific hardware, which receives data at port 7715, sends answers to udp port 7714, ports can't be changed. Piece of code below:</p>
  
  <pre><code>&lt;?php
  $socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
  
  if (!socket_bind($socket, '192.168.1.254', 7714)){
      echo socket_strerror(socket_last_error($socket));
  }
  
  socket_connect($socket, '192.168.1.150', 7715);
  if (!socket_listen($socket, 5)){
      echo socket_strerror(socket_last_error($socket));
  }
  
  $arr = [0x23, 0x00, 0x0C, 0x0E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06];
  $checksum = 0x00 - array_sum($arr);
  $str = implode(', ', $arr);
  
  $eval = '$buffer = ' . "pack('c*', $str, $checksum);";
  eval($eval);
  
  socket_write($socket, $buffer);
  </code></pre>
  
  <p>Firewall disabled, Wireshark shows, that everything is OK:</p>
  
  <blockquote>
    <p>1  0.000000    192.168.1.254   192.168.1.150   UDP 54  65213 → 7715 Len=12</p>
    
    <p>2  0.005611    192.168.1.150   192.168.1.254   UDP 78  7715 → 7714 Len=36</p>
  </blockquote>
  
  <p>Somehow, PHP can bind this socket to any udp port, but not to 7714. </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>
    
    <p>Warning: socket_listen(): unable to listen on socket [10045]: The attempted operation is not supported for the type of object referenced.</p>
  </blockquote>
  
  <p>What can be wrong?</p>