//This method is used to initialize the client by sending rfc details to the server int initClient(int sockfd){ printf("Initializing client\n"); FILE *fp; int id,numbytes; char title[256]; char* buf; fp = fopen("index.txt","r"); if(fp == NULL){ perror("Rfc index not found"); exit(-1); } while(fscanf(fp,"%d %[^\t\n]",&id,title) == 2){ //Send add requests to the server reqHeader(sockfd,ADD,id,title); buf=(char *)malloc(MAXDATASIZE); numbytes = recv(sockfd,buf,MAXDATASIZE-1,0); buf[numbytes] = '\0'; printf("Response from server : %s\n\n",buf); } fclose(fp); return 0; }
int sendList(int sockfd){ char* buf; int numbytes; reqHeader(sockfd,LISTALL,NULL,NULL); buf=(char *)malloc(MAXDATASIZE); numbytes = recv(sockfd,buf,MAXDATASIZE-1,0); buf[numbytes] = '\0'; printf("Response from server : %s\n",buf); }
int sendLookup(int sockfd, int rfcid){ char* buf; int numbytes; reqHeader(sockfd,LOOKUP,rfcid,NULL); buf=(char *)malloc(MAXDATASIZE); numbytes = recv(sockfd,buf,MAXDATASIZE-1,0); buf[numbytes] = '\0'; printf("Response from server : %s\n\n",buf); }
bool CDataStreamLayer::MakeTransaction( unsigned char aMode, const l2max::CByteArray& aParam, l2max::CByteArray& aResp ) { bool ret( false ); l2max::CByteArray req; l2max::CBuffer reqStream( &req ); reqStream << reqHeader( sizeof( aMode ) + aParam.size() ); reqStream << aMode; reqStream << aParam; reqStream << CDataStreamLayer::checkSum( req ); if( ret = _adapter.Write( req ) ) { l2max::CByteArray resp; resp.Resize( _maxResponseLength ); if( ret = _adapter.Read( resp ) ) { if( resp.size() ) { unsigned char checkSum( resp.back() ); resp.Pop_back(); if( checkSum != CDataStreamLayer::checkSum( resp ) ) { _errorCode = ecBinaryError; } if( _errorCode == ecNoError ) { l2max::CBuffer respStream( &resp ); unsigned char respEcuId( 0 ); unsigned char respMsgLength( 0 ); respStream >> respEcuId; respStream >> respMsgLength; if( respEcuId == ecuId() ) { l2max::CByteArray resp; respStream >> resp; if( resp.size() != decLength( respMsgLength ) ) { _errorCode = ecBinaryError; } if( _errorCode == ecNoError ) { l2max::CBuffer respStream( &resp ); unsigned char respMode( 0 ); respStream >> respMode; if( respMode == aMode ) { respStream >> aResp; } else {
int sendGet(int sockfd,int rfcid){ printf("Get request for : %d\n",rfcid); reqHeader(sockfd,GET,rfcid,NULL); }