bool ATTrie :: retreive(const QString & key, const StemNode** node) { if (node == NULL) return false; int index; bool ret= retreive(key,&index); if (ret) { if (*node==NULL) *node=new const StemNode(); *node=&(database_info.trie_nodes->at(index)); } return ret; }
int main(int argc, char *argv[]) { int sock, n; unsigned int length; struct sockaddr_in server, from; struct hostent *hp; char buf[50]; short connection_id = -1; short type = 1; short status = 0; char buffer[20]; printf("Enter the path\n"); //enter the remote file path scanf("%s",buffer); encode(connection_id,type,status,buffer,buf); //printf("%s",buf); if (argc != 3) { printf("Usage: server port\n"); exit(1); } sock= socket(AF_INET, SOCK_DGRAM, 0); if (sock < 0) error("socket"); server.sin_family = AF_INET; hp = gethostbyname(argv[1]); if (hp==0) error("Unknown host"); bcopy((char *)hp->h_addr, (char *)&server.sin_addr, hp->h_length); server.sin_port = htons(atoi(argv[2])); length=sizeof(struct sockaddr_in); /*printf("Please enter the message: "); bzero(buffer,256); fgets(buffer,255,stdin);*/ n=sendto(sock,buf, strlen(buf),0,(const struct sockaddr *)&server,length); if (n < 0) error("Sendto"); n = recvfrom(sock,buf,50,0,(struct sockaddr *)&from, &length); if (n < 0) error("recvfrom"); retreive(buf,&connection_id,&type,&status,buffer); if(type==2) { write(1,"Got REQUEST_ACK: ",17); write(1,buf,n); printf("\n"); n = recvfrom(sock,buf,50,0,(struct sockaddr *)&from, &length); if (n < 0) error("recvfrom"); retreive(buf,&connection_id,&type,&status,buffer); if(type==3) { write(1,"Got DONE: ",10); write(1,buf,n); printf("\n"); printf("Sending DONE_ACK\n"); connection_id=14; type=4; status=0; int j=0; while(buffer[j]!='\0') { buffer[j]='0'; j++; } encode(connection_id,type,status,buffer,buf); n=sendto(sock,buf, strlen(buf),0,(const struct sockaddr *)&server,length); if (n < 0) error("Sendto"); } } close(sock); return 0; }