another question for the continuing saga ..
I am trying to undertake a handshake with the telnet (tn3270) server ..
using
$get=socket_read($socket, 128, PHP_BINARY_READ );
i now need to step through $get byte by byte
how do i do an equivilent fgetc? ie

  while (!feof($get)) {
echo fgetc($iget);
}

but with the socket???

entire code below. ...
cheers

brendan








-----------------------


<?php
################ SET BINARY CODES #############################

  function makeChr($loud="off"){
  for ($i = 0; $i < 256; ++$i) {
  static $genNum;
  $genNum++;
  $bin_array[$genNum]=(chr($genNum));
      if ($loud=="on") {
          echo "chr($genNum) will output '";
          echo (chr($genNum));
          echo "'<br> \n";
      }
  }
  return $bin_array;

}
$bin_array= makeChr();

     $chr_array[0]="NUL"; /*                                    NULL 
(NUL)              0      No Operation    */

     $chr_array[1]="ARE";               //        1


    $chr_array[7]="BELL";          /*               Produces an audible or
                                         visible signal (which does
                                         NOT move the print head).*/

         $chr_array[7]="BS";     /*    Moves the print head one
                                         character position towards
                                         the left margin.   */
         $chr_array[9]="HT";  /*    Moves the printer to the
                                         next horizontal tab stop.
                                         It remains unspecified how
                                         either party determines or
                                         establishes where such tab
                                         stops are located. */
         $chr_array[10]="LF"; /*      Line Feed ()              Moves 
the printer to the
                                         next print line, keeping the
                                         same horizontal position.   */

         $chr_array[11]="VT"; /*   Moves the printer to the
                                         next vertical tab stop.  It
                                         remains unspecified how
                                         either party determines or
                                         establishes where such tab
                                         stops are located.   */
          $chr_array[12]="FF"; /*    Moves the printer to the top
                                         of the next page, keeping
                                         the same horizontal position. */

         $chr_array[13]="CR"; /* Carriage Return (CR)   13      Moves 
the printer to the left
                                         margin of the current line.     */



          $chr_array[29]="3270-REGIME"; /*  Telnet 3270 Regime Option
                                          rfc 
http://www.ietf.org/rfc/rfc1041.txt
                                        */

   $chr_array[240]="SE";                  /*       End of subnegotiation 
parameters. */

       $chr_array[241]="NOP";                     /* No operation. */

       $chr_array[242]="Data Mark";                   /*  The data 
stream portion of a Synch.*/
                                 /* This should always be accompanied */
                                  /* by a TCP Urgent notification.*/
      $chr_array[243]="Break";                    /* NVT character BRK.*/
      $chr_array[244]="Interrupt Process";         /* The function IP.*/
      $chr_array[245]="Abort output";             /* The function AO.*/
      $chr_array[246]="Are You There";            /*  The function AYT.*/
      $chr_array[247]="Erase character"; /* The function EC. */
      $chr_array[248]="Erase Line";               /* The function EL.*/
      $chr_array[249]="Go ahead"; /* The GA signal. */
      $chr_array[250]="SB";       /* Indicates that what follows is
                                  subnegotiation of the indicated
                                  option. */
      $chr_array[251]="WILL";   /* Indicates the desire to begin
                                  performing, or confirmation that
                                  you are now performing, the
                                  indicated option.    */

      $chr_array[ 252]="WON'T";     /* Indicates the refusal to perform,
                                  or continue performing, the
                                  indicated option. */

      $chr_array[253]="DO";    /* Indicates the request that the
                                  other party perform, or
                                  confirmation that you are expecting
                                  the other party to perform, the
                                  indicated option. */

       $chr_array[254]="DON\'T";   /*Indicates the demand that the
                                  other party stop performing,
                                  or confirmation that you are no
                                  longer expecting the other party
                                  to perform, the indicated option. */
      $chr_array[255]="IAC";     //Data Byte 255.





################ SET BINARY CODES #############################

error_reporting (E_ALL);
$port = '23';
$address = '202.14.186.30';

/* Create a TCP/IP socket. */
$socket = socket_create (AF_INET, SOCK_STREAM, 0);
if ($socket < 0) {
     echo "socket_create() failed: reason: " . socket_strerror ($socket) 
. "\n";
} else {
     "socket_create() successful:\n";
}

echo "Attempting to connect to '$address' on port '$port'...";
$result = socket_connect ($socket, $address, $port);
if ($result < 0) {
     echo "socket_connect() failed.\nReason: ($result) " . 
socket_strerror($result) . "\n";
} else {
     echo "<BR>OK.\n";
}

$get=socket_read($socket, 128, PHP_BINARY_READ );

      $tmp = fgetc($get);
      $tmp=array_search ($tmp,$bin_array);

      if ($tmp) echo "<BR>".$chr_array[$tmp]."<BR>";


echo "Closing socket...";
socket_close ($socket);
echo "OK.\n\n";

?>
----------------


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to