Simple? winsock client - server problem
I've created a simple winsock program, where i send a string from the client to the server. The problem is that the server enters an infinite loop, and receives the same string over and over again.. What's the error here(The functions are standard Winsock, th "lp"-prefix is because i'm linking explicit)?
Client:
Code:
do{
cout<<"Enter data to send:\n";
memset(buf, 0, 100);
cin.getline(buf,100, '\n');
if(send(theSocket, buf, strlen(buf), MSG_DONTROUTE) == SOCKET_ERROR){
errHand("Error at send()");
}else{
recv(theSocket, buf, 100, MSG_DONTROUTE);
cout<<"Status: "<<buf<<"\n";
}
}while(buf[0] != 'q');
Server:
Code:
// Send/receive from the client:
while(buf[0] != 'q'){
memset(buf, 0, 100);
if((iBytes=lpRecv(theClient, buf, 100, MSG_PEEK)) == SOCKET_ERROR)
SendMessage(dat1->list1, LB_ADDSTRING, 0, (long)"Error at recv()");
else if(iBytes>0){
buf[iBytes]='\0';
sprintf(buf, "n:%i: %s", iBytes, buf);
SendMessage(dat1->list1, LB_ADDSTRING, 0, (long)buf);
strcpy(buf, "o");
lpSend(theClient, buf, strlen(buf), MSG_DONTROUTE);
}else
buf[0]='\0';
}