C: TCP server doesnt receive the whole message -


hello im trying make server receive message :"str1\0str2\0str3\0" , separate in substrings. on client side seems work fine when im receiving message on server side receive "str1". appreciated thanks!

server:

   bzero(buffer,256);    n = read( newsockfd,buffer, 255 );     if (n < 0) {       perror("error reading socket");       exit(1);    }     printf("here message: %s\n",buffer);      for(int = 0; < strlen(buffer); i++){        printf("%c", buffer[i],i);        if ( buffer[i] == 0 ){        printf("0");      }    }` 

client:

   char buffer[256];    int length =0;    char *uptr = buffer;    int i;         strcpy(uptr,argv[3]);        length = length + strlen(argv[3])-3;         ( = 4 ; < argc  ; i++){            memcpy(uptr+length+i, argv[i]  ,strlen(argv[i]) +1);            length = length + strlen(argv[i]);         }         buffer[length + (argc - 1)]= 0;          for(i = 0; < length + argc; i++){            printf("%c", buffer[i],i);         } 

you never wrote code receive message. it's not surprising code doesn't receive message.

  bzero(buffer,256);   n = read( newsockfd,buffer, 255 ); 

this reads data might or might not message. after all, read function has no idea messages like.

printf("here message: %s\n",buffer); 

wait, what? makes message? bytes read connection. it's not message.

you need write code receive message, otherwise won't receive messages bunch of bytes connection.


Comments

Popular posts from this blog

inversion of control - Autofac named registration constructor injection -

verilog - Systemverilog dynamic casting issues -

ios - Change Storyboard View using Seague -