int main() { int n,t; char x; //check connection while(create_connection(5500,"127.0.0.1")==FAIL){ printf("Ban co muon thu ket noi lai?[y]\n"); x=getchar(); while(getchar()!='\n'); if (x=='y'||x=='Y')continue; else return 0; } protocol p; while(1){ // bien t de check trang thai cua signup in_menu(); scanf("%d",&n); while(getchar()!='\n'); if(n==3) break; switch(n){ case 1: c_login(&p); break; case 2: t=c_signup(&p); break; } if(t==SIGNUP_FAIL) continue; // k trung pass send(sockfd,&p,sizeof(protocol),0); recv(sockfd,&p,sizeof(protocol),0); switch(p.flag){ case SUCCESS: printf("\nLogin success!!\n"); start(p); break; case NO_ACCOUNT: printf("\n%s",LOGIN_ERROR); break; case LOGIN_FAIL: printf("\n%s",LOGIN_ERROR); break; case SIGNUP_FAIL: printf("\n%s",SIGNUP_ERROR2); } } close(sockfd); }
int main() { create_connection(5500,"127.0.0.1"); int n,t; protocol p; while(1) { // bien t de check trang thai cua signup t=-1; in_menu(); scanf("%d",&n); while(getchar()!='\n'); if(n==3) break; switch(n) { case 1: c_login(&p); break; case 2: t=c_signup(&p); break; } if(t==SIGNUP_FAIL) continue; send(sockfd,&p,sizeof(protocol),0); recv(sockfd,&p,sizeof(protocol),0); switch(p.flag) { case SUCCESS: printf("\nLogin success!!\n"); start(p); break; case NO_ACCOUNT: printf("\n%s",LOGIN_ERROR); break; case LOGIN_FAIL: printf("\n%s",LOGIN_ERROR); break; case SIGNUP_FAIL: printf("\n%s",SIGNUP_ERROR2); } } }