sockets
-
something wrong with my func(I marked probkem arrea) : char buf[MAXCODE]; ClearString(buf); //Send "BEGINRECV" if(!send(Client,"BRCV",MAXCODE,0)) return ERR; //Request query if(!recv(Client,buf,MAXCODE,0)) return ERR; if (strnicmp(buf,"SUCC",4) != 0) return NOREQUEST; ClearString(buf); //Send "SIZE" if (!send(Client,"SIZE",MAXCODE,0)) return ERR; //Request query if(!recv(Client,buf,MAXCODE,0)) return ERR; if (strnicmp(buf,"SUCC",4) != 0) return NOREQUEST; ClearString(buf); char *recvSize; recvSize = new char[MAXMESS]; ClearString(recvSize); //Recieve SIZE if(!recv(Client,recvSize,4,0)) return ERR; if(!send(Client,"SUCC",MAXCODE,0)) return NOREQUEST; int size = StringToInt(recvSize); delete [] recvSize; char *data; data = new char[size]; ClearString(data); // Here recv recieves "BRCV" whatever server sends. If server doesnot send anything it anyway recieves "BRCV" // It always recieves "BRCV" if(!recv(Client,data,size,0)) return ERR; if(!send(Client,"SUCC",MAXCODE,0)) return NOREQUEST; fData.Empty(); fData = data; fData.Insert(size, '\0'); delete [] data; //Send "ENDRECV" if(!send(Client,"ERCV",MAXCODE,0)) return ERR; //Request query if(!recv(Client,buf,MAXCODE,0)) return ERR; if (strnicmp(buf,"SUCC",4) != 0) return NOREQUEST; ClearString(buf);
-
something wrong with my func(I marked probkem arrea) : char buf[MAXCODE]; ClearString(buf); //Send "BEGINRECV" if(!send(Client,"BRCV",MAXCODE,0)) return ERR; //Request query if(!recv(Client,buf,MAXCODE,0)) return ERR; if (strnicmp(buf,"SUCC",4) != 0) return NOREQUEST; ClearString(buf); //Send "SIZE" if (!send(Client,"SIZE",MAXCODE,0)) return ERR; //Request query if(!recv(Client,buf,MAXCODE,0)) return ERR; if (strnicmp(buf,"SUCC",4) != 0) return NOREQUEST; ClearString(buf); char *recvSize; recvSize = new char[MAXMESS]; ClearString(recvSize); //Recieve SIZE if(!recv(Client,recvSize,4,0)) return ERR; if(!send(Client,"SUCC",MAXCODE,0)) return NOREQUEST; int size = StringToInt(recvSize); delete [] recvSize; char *data; data = new char[size]; ClearString(data); // Here recv recieves "BRCV" whatever server sends. If server doesnot send anything it anyway recieves "BRCV" // It always recieves "BRCV" if(!recv(Client,data,size,0)) return ERR; if(!send(Client,"SUCC",MAXCODE,0)) return NOREQUEST; fData.Empty(); fData = data; fData.Insert(size, '\0'); delete [] data; //Send "ENDRECV" if(!send(Client,"ERCV",MAXCODE,0)) return ERR; //Request query if(!recv(Client,buf,MAXCODE,0)) return ERR; if (strnicmp(buf,"SUCC",4) != 0) return NOREQUEST; ClearString(buf);
have you ever tried to send a string that was containing white spaces...? the string is not sent entierly. if you do this :
strcpy(strBuf, "hello world!");
send(sockfd, strBuf, strlen(strBuf), 0);you will have "hello" received, then at the next
recv()
call on the peer, "world!" will be get. it looks the same thing here. are you sure you don't send a white spaced string ?
TOXCCT >>> GEII power