Jump to content

OmegaNemesis

New Members
  • Posts

    1
  • Joined

  • Last visited

Everything posted by OmegaNemesis

  1. I am trying to connect to a server socket which will send me a bunch of data after connecting, take a response from me, and then send a bunch more data, repeating this process until it determines its had enough. So basically, after first~ connecting, we will (and currently are) receiving data from the server. We want to take this data, compute it in another script/program passing with AJAX, and then return to this and respond to the server. We're afraid that once we take data from the server, go to compute the data, the socket is going to close and we're not going to be able to continue where we left off. How can we make sure that php persists in its connection to this socket? I've looked into fsockopen and I'm not quite understanding of it and whether it will help here or not. Any assistance? // create socket //$socket = socket_create(AF_INET, SOCK_STREAM, 0) or die("Could not create socket\n"); $socket = fsockopen($host, $port, $errno, $errstr, 30); if (!$socket) { echo "$errstr ($errno)<br />\n"; } $_SESSION['socket'] = $socket; // receive DATA from server //$result = socket_connect($socket, $host, $port) or die("Could not connect to server\n"); echo "Connected to server"; //$_SESSION['connection'] = $result;\ //STOP, PASS DATA, COMPUTE, SEND RESPONSE // send response to server fwrite($socket, $message1) or die("Could not send data to server\n"); // get data server response $result = fread ($socket, 1024) or die("Could not read server response\n"); echo "<br>Reply From Server :".$result; // close socket fclose($socket);
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.