home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 8 Other / 08-Other.zip / SERVER.ZIP / CLIENT.BAK next >
Text File  |  1993-02-22  |  3KB  |  74 lines

  1. #include <stdlib.h>
  2. #include <malloc.h>
  3. #include <time.h>
  4. #include <io.h>
  5. #include <fcntl.h>
  6. #include <sys\types.h>
  7. #include <sys\stat.h>
  8.  
  9. #define USHORT       unsigned short
  10. #define ULONG        unsigned long
  11. #define CHAR         char
  12. #define BYTE         unsigned char
  13.  
  14. main ( int argc, char **argv )
  15.  
  16. { int     hfile;
  17.   CHAR    PipeName [ 256 ], HandShake[256];
  18.   CHAR    Buffer [ 8192 ], FName [ 256 ];
  19.   ULONG   ulAction, BytesToRead, TotBytes, ulFileSize, ulFNameLen;
  20.   ULONG   OpenFlag, BytesRead, BytesWritten;
  21.   USHORT  rc;
  22.   double  beg_time, end_time;
  23.  
  24.   printf ( "CLIENT: Client Process has now started!\n" );
  25.   if ( argc != 2 ) {
  26.     printf ( "CLIENT ERROR: Invalid number of arguements. Pipe Name must be\n" );
  27.     printf ( "              specified on the commnad line.\n" );
  28.     exit(-1);
  29.   } /* endif */
  30.  
  31.   strcpy ( PipeName, *++argv );
  32.   printf ( "CLIENT: Wait for the Instance of the pipe %s \n", PipeName );
  33.  
  34.   hfile = open ( PipeName, O_RDWR | O_BINARY, S_IREAD | S_IWRITE );
  35.   if ( hfile <= 0 ) {
  36.     printf ( "CLIENT: Error opening the Pipe in Client \n" );
  37.     printf ( "CLIENT: rc = %x \n", rc );
  38.     exit ( -1 );
  39.   } /* endif */
  40.  
  41.   write ( hfile, "READY", 6 );
  42.   printf ( "CLIENT: Sent handshake to the Server! \n" );
  43.   read ( hfile, &ulFNameLen, sizeof(ULONG));
  44.   printf ( "CLIENT: Length of the File Name = %d \n", ulFNameLen );
  45.   read ( hfile, FName, (USHORT) ulFNameLen );
  46.   printf ( "CLIENT: File to transfer is %s \n", FName );
  47.   read ( hfile, &ulFileSize, sizeof(ULONG));
  48.   printf ( "CLIENT: Size of file to transfer in bytes is %ld \n", ulFileSize );
  49.  
  50. /********************************************************************************/
  51. /* Loop and read the data in 4K blocks until there will be less than 4K         */
  52. /* left to receive and then read the appropriate size block.  We are            */
  53. /* reading 4K blocks because the buffer has been set to 4K.  This can be        */
  54. /* changed to a larger size in the DosCreateNPipe() call in the SERVER process. */
  55. /********************************************************************************/
  56.   BytesToRead = 8192;
  57.   TotBytes = ulFileSize;
  58.   beg_time = (double) clock ();
  59.   while ( BytesToRead <= TotBytes ) {
  60.     read ( hfile, Buffer, (USHORT) BytesToRead );
  61.     TotBytes -= BytesToRead;
  62.   } /* end while */
  63.   if ( TotBytes > 0 )
  64.     read ( hfile, Buffer, (USHORT) TotBytes );
  65.   end_time = (double) clock ();
  66.  
  67.   printf ( "CLIENT: Done! %ld Bytes were transferred by the pipe \n", ulFileSize );
  68.   printf ( "CLIENT: Transfer took %2.4f seconds\n",
  69.            ( end_time - beg_time ) / (double) CLOCKS_PER_SEC );
  70.   printf ( "CLIENT: Transfer speed was %10.4f bytes/second\n",
  71.            (double) ulFileSize / ((end_time-beg_time) / (double) CLOCKS_PER_SEC));
  72.   exit(0);
  73. } /* end of CLIENT() */
  74.