Skip to content

Latest commit

 

History

History
37 lines (30 loc) · 786 Bytes

readme.md

File metadata and controls

37 lines (30 loc) · 786 Bytes

Collection of classes for server and client to connect via non blocking sockets.

Server Usage

  try {
    $socketServer = new ServerSocket($port, $handleRequest);
  } catch (Exception $e) {
     //exception handling
  }
  while(true) {

    $socketServer->checkForIncoming(.1);
    $socketServer->readAndWrite(.1);

    //do stuff
  }

Client Usage

    try { 
      $connection = new ClientSocket('localhost', $serverPort, 10);
    } catch(Exception $e) {
      //exception handling
    }

    $connection->setWaitTimeout($timeout);
    $sendResult = $connection->sendRequest(json_encode($data));

    if($sendResult === false) {

      $connection->closeConn();
      return false;
    }

    $reply = $connection->getReply();
    $connection->closeConn();