home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 8 Other
/
08-Other.zip
/
SERVER.ZIP
/
CLIENT.BAK
next >
Wrap
Text File
|
1993-02-22
|
3KB
|
74 lines
#include <stdlib.h>
#include <malloc.h>
#include <time.h>
#include <io.h>
#include <fcntl.h>
#include <sys\types.h>
#include <sys\stat.h>
#define USHORT unsigned short
#define ULONG unsigned long
#define CHAR char
#define BYTE unsigned char
main ( int argc, char **argv )
{ int hfile;
CHAR PipeName [ 256 ], HandShake[256];
CHAR Buffer [ 8192 ], FName [ 256 ];
ULONG ulAction, BytesToRead, TotBytes, ulFileSize, ulFNameLen;
ULONG OpenFlag, BytesRead, BytesWritten;
USHORT rc;
double beg_time, end_time;
printf ( "CLIENT: Client Process has now started!\n" );
if ( argc != 2 ) {
printf ( "CLIENT ERROR: Invalid number of arguements. Pipe Name must be\n" );
printf ( " specified on the commnad line.\n" );
exit(-1);
} /* endif */
strcpy ( PipeName, *++argv );
printf ( "CLIENT: Wait for the Instance of the pipe %s \n", PipeName );
hfile = open ( PipeName, O_RDWR | O_BINARY, S_IREAD | S_IWRITE );
if ( hfile <= 0 ) {
printf ( "CLIENT: Error opening the Pipe in Client \n" );
printf ( "CLIENT: rc = %x \n", rc );
exit ( -1 );
} /* endif */
write ( hfile, "READY", 6 );
printf ( "CLIENT: Sent handshake to the Server! \n" );
read ( hfile, &ulFNameLen, sizeof(ULONG));
printf ( "CLIENT: Length of the File Name = %d \n", ulFNameLen );
read ( hfile, FName, (USHORT) ulFNameLen );
printf ( "CLIENT: File to transfer is %s \n", FName );
read ( hfile, &ulFileSize, sizeof(ULONG));
printf ( "CLIENT: Size of file to transfer in bytes is %ld \n", ulFileSize );
/********************************************************************************/
/* Loop and read the data in 4K blocks until there will be less than 4K */
/* left to receive and then read the appropriate size block. We are */
/* reading 4K blocks because the buffer has been set to 4K. This can be */
/* changed to a larger size in the DosCreateNPipe() call in the SERVER process. */
/********************************************************************************/
BytesToRead = 8192;
TotBytes = ulFileSize;
beg_time = (double) clock ();
while ( BytesToRead <= TotBytes ) {
read ( hfile, Buffer, (USHORT) BytesToRead );
TotBytes -= BytesToRead;
} /* end while */
if ( TotBytes > 0 )
read ( hfile, Buffer, (USHORT) TotBytes );
end_time = (double) clock ();
printf ( "CLIENT: Done! %ld Bytes were transferred by the pipe \n", ulFileSize );
printf ( "CLIENT: Transfer took %2.4f seconds\n",
( end_time - beg_time ) / (double) CLOCKS_PER_SEC );
printf ( "CLIENT: Transfer speed was %10.4f bytes/second\n",
(double) ulFileSize / ((end_time-beg_time) / (double) CLOCKS_PER_SEC));
exit(0);
} /* end of CLIENT() */