Salve ho un problema... In poche parole il client deve inviare 2 stringhe al server che deve concatenare e inviare al cliente per la visualizzazione... vi posto il codice
codice:
Client.C
typedef struct Messaggio{
char a[BUFFERSIZE];
char b[BUFFERSIZE];
} msgStruct;
msgStruct msg;
//.... settaggi vari....
printf("Inserisci Stringa 1:");
scanf("%s",msg.a);
printf("Inserisci Stringa 2:");
scanf("%s",msg.b);
stringLen=sizeof(msg);
//invio
if (send(Csocket, &msg, stringLen, 0) != stringLen) {
ErrorHandler("send() sent a different number of bytes than expected");
closesocket(Csocket);
ClearWinSock();
return 0;}
//ricevo
int bytesRcvd;
int totalBytesRcvd = 0;
char buf[BUFFERSIZE]; // buffer for data from the server
printf("RICEVUTO: "); // Setup to print the echoed string
while (totalBytesRcvd < stringLen) {
if ((bytesRcvd = recv(Csocket, buf, BUFFERSIZE - 1, 0)) <= 0) {
ErrorHandler("recv() failed or connection closed prematurely");
closesocket(Csocket);
ClearWinSock();
return 0;
}
totalBytesRcvd += bytesRcvd; // Keep tally of total bytes
buf[bytesRcvd] = '\0'; // Add \0 so printf knows where to stop
printf("%s", buf); // Print the echo buffer
}
codice:
Sever.c
typedef struct Messaggio{
char a[BUFFERSIZE];
char b[BUFFERSIZE];
} msgStruct;
msgStruct msg;
//.... settaggi vari....
recv(serverSocket,&msg,BUFFERSIZE -1,0);
serverLen=sizeof(&msg);
send(serverSocket,strcat(msg.a,msg.b),sizeof(msgStruct), 0);
se in INPUT inserisco :
stringa 1 :ff
stinga 2 : cc
in OUTPUT dovrei avere:
RICEVUTO:ffcc
il mio reale risultato è
RICEVUTO: ff
Non capisco il problema sinceramente....mi sapete dare una mano