title: How to receive data from server using PHP socket
body: <p>I am having a hard time getting data from the server. Basically server waits for a connection from anyone using correct username and password. So when I use that using local explorer it shows the data on the browser.
  <a href="https://i.stack.imgur.com/juuf4.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/juuf4.jpg" alt="enter image description here"></a></p>
  
  <p>Now what I was trying to do is, get this data using socket and forward it to another server address. But I could not even connect to the server to get the data like I get on the browser. Here is what I have tried:</p>
  
  <pre><code>$host = "192.168.1.4/online?user=dneb&amp;pass=mella88";
  $port = 1850;
  // don't timeout!
  set_time_limit(0);
  // create socket
  $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP) or die("Could not create socket\n");
  // bind socket to port
  $result = socket_bind($socket, $host, $port) or die("Could not bind to socket\n");
  // start listening for connections
  $result = socket_listen($socket, 3) or die("Could not set up socket listener\n");
  
  // accept incoming connections
  // spawn another socket to handle communication
  $spawn = socket_accept($socket) or die("Could not accept incoming connection\n");
  // read client input
  $input = socket_read($spawn, 1024) or die("Could not read input\n");
  // clean up input string
  $input = trim($input);
  echo "server Message : ".$input;
  </code></pre>
  
  <p>When I run this code I get warning message:</p>
  
  <blockquote>
    <p>Warning: socket_bind(): Host lookup failed [11004]: The requested name is valid, but no data of the requested type was found. in C:\xampp\htdocs\socket\client.php on line 10
    Could not bind to socket</p>
  </blockquote>
  
  <p>Or suggest other methods to use.</p>