/********************************************************************************************************* "Ensemble" is the proprietary property of The Regents of the University of California ("The Regents.") Copyright (c) 2005-10 The Regents of the University of California, Davis campus. All Rights Reserved. Redistribution and use in source and binary forms, with or without modification, are permitted by nonprofit, research institutions for research use only, provided the conditions in the included license agreement are met. Refer to the file "ensemble_license.txt" for the license agreement, located in the top level directory of this distribution. **********************************************************************************************************/ /* * Dumb test client for matrpc * * This is completely disposable but can serve as an example of how * to communicate with matrpc. * * 2/15/07 DH Edit * Added while loop to allow for multiple command line buffers to be sent * until 'exit' or 'quit' is requested. */ #include #include #include #include #include #include #include #include #include #include #include #define SOCKET short int main( int argc, char *argv[] ) { if( argc < 3 ) { printf( "client \n\n" ); exit(1); } SOCKET sock; char* listenIPAddress = argv[1]; printf("%s",listenIPAddress); int listenPort = atoi( argv[2] ); int res, x; struct sockaddr_in serverInfo; serverInfo.sin_family = AF_INET; serverInfo.sin_addr.s_addr = inet_addr( listenIPAddress ); serverInfo.sin_port = htons(listenPort); char buf[512]; sock = socket( AF_INET, SOCK_STREAM, 0 ); res = connect(sock,(struct sockaddr *)&serverInfo,sizeof(serverInfo)); char resBuf[512]; printf( "cmd> " ); char tempBuf[ 256 ]; scanf( "%s", tempBuf ); /* if( !strncmp( tempBuf, "exit", 4 ) || !strncmp( tempBuf, "quit", 4 ) ) { break; } */ while ( tempBuf != "exit" ) { sprintf( buf, "%s", tempBuf ); printf( "send -->%s<--\n", buf ); res = send( sock, buf, strlen(buf)+1, 0 ); printf( "Sent %d bytes to %s\n", res, listenIPAddress ); printf( "Waiting for response...\n\n"); res = recv( sock, resBuf, 512, 0 ); printf( "Received %d bytes from %s\n", res, listenIPAddress ); resBuf[res] = '\0'; printf( "received -->%s<--\n\n", resBuf ); printf( "cmd> " ); scanf( "%s", tempBuf ); if( !strncmp( tempBuf, "exit", 4 ) || !strncmp( tempBuf, "quit", 4 ) ) { break; } } close(sock); return(0); }