My code is
//server.c
main(int argc, char *argv[]){
//setup socket
// socket() - bind() -listen()
while(1)
{
clientptr = (struct sockaddr *)&client;
clientlen = sizeof client;
while((newsock = accept(sock,clientptr,&clientlen)) < 0 );
printf("\n\nNew connection.\n");
switch(fork()){
case -1 :
printf("server fork failure %d\n",errno);
perror("Server: ");
exit(1);
case 0 :
do{
read(newsock,buf,sizeof buf);
if(strcmp(buf,"one")==0)
{
printf("\n one \n");
}
}while(strcmp(buf,"quit")!=0)
}//end while(1)
}
//client
main(int argc,char *argv[])
{
//socket()-connect() ...
do{
menu(); //display choices
choice = get_choice(); //return an integer
switch(choice)
{
case 1: write(sock,buf,sizeof buf,"one");
break;
case 2: write(sock,buf,sizeof buf,"quit");
break;
}
}
//....
}
First time I press 1 so server prints one.
Then, the menu is appearing again, but when I press 1 server does not print anything.
Could anyone help me fix it ?
Thanks a lot


Sign In
Create Account

Back to top









