   recving gibberish...
  first time using async socketsboth the server and the client is recving the (char)1 which they're supposed to but once in a while, there's always this bit of data which i didn't intentionally send that appearsWhere's all that extra data coming from?   case FD_WRITE:  if (!SendBuffer.empty())  { BytesSent = send(wParam, SendBuffer.c_str(), SendBuffer.size(), 0); if (BytesSent == -1) {if (WSAGETSELECTERROR(lParam) == WSAEWOULDBLOCK){    std::cout&lt;&lt;"WSAEWOULDBLOCK"&lt;&lt;std::endl;    return true;}else{    MessageBox(g_hwnd, "int C_Network::HandleMessages(WPARAM wParam, LPARAM lParam) \n send failed \n 1", "ERROR", MB_OK);} } if (BytesSent &lt; SendBuffer.size()) {MessageBox(g_hwnd, "int C_Network::HandleMessages(WPARAM wParam, LPARAM lParam) \n (BytesSent &lt; SendBuffer.size())", "WARNING", MB_OK);//send the rest... } std::cout&lt;&lt;SendBuffer.c_str(); SendBuffer.clear();  }  while(true)  { std::string s; s.clear(); s += (char)1; //if (send(wParam, "\0", sizeof("\0"), 0) == -1) if (send(wParam, s.c_str(), s.size(), 0) == -1) {if (WSAGetLastError() == WSAEWOULDBLOCK)//if (WSAGETSELECTERROR(lParam) == WSAEWOULDBLOCK){    break;}else{    MessageBox(g_hwnd, "int C_Network::HandleMessages(WPARAM wParam, LPARAM lParam) \n send failed \n 2", "ERROR", MB_OK);    std::cout&lt;&lt;WSAGETSELECTERROR(lParam)&lt;&lt;std::endl;} }  }  break;   case FD_READ:   {  recv(wParam, temprecv, sizeof(temprecv), 0);  std::string a(temprecv);/*  for (int i = 0; i &lt; sizeof(temprecv); i++)  { //if (temprecv != '\0') if (temprecv != (char)1) {RecvBuffer.push_back(temprecv);putchar(temprecv); }  }*/  for (int i = 0; i &lt; a.size(); i++)  { //if (temprecv != '\0') if (a != (char)1) {RecvBuffer.push_back(a);//putchar(a); }  }  this-&gt;ProcessRecv();  break;   }ProcessRecv()    if (RecvBuffer.empty())    {   return;    }    int i = (int)RecvBuffer[0];    while (i &lt;= 1)    {   RecvBuffer.pop_front();   if (RecvBuffer.empty())  return;   i = RecvBuffer[0];    }    if (i &gt; RecvBuffer.size()-1) //if we didnt recieve everything    {   return;    }    RecvBuffer.pop_front(); //remove message size    for (i; i &gt; 0; i--)    {   putchar(RecvBuffer[0]);   RecvBuffer.pop_front();    }[Edited by - h_howee on August 31, 2007 6:00:28 AM]
  [source] [/source] tags make this much more readable.   ; std::string s; s.clear(); s += (char)1; //if (send(wParam, "\0", sizeof("\0"), 0) == -1) if (send(wParam, s.c_str(), s.size(), 0) == -1)That looks wrong. It's not a NULL-terminated string, I think. size() can be anything.try s += "1"; instead[Edited by - oliii on August 31, 2007 2:23:39 AM];  As you can see, I've tried sending \0 but that give me even more gibberish outputi thought i was supposed to use  tags;  Sending s.c_str() with s.size() is fine of itself; it won't send the terminating 0.However, if you're using TCP, then you're not framing the stream in a parseable manner, because the receiving side doesn't know how much to read for any given string, compared to the start of the next string. The Forum FAQ mentions this very problem, with solutions.;Quote:Original post by hplus0603The Forum FAQ mentions this very problem, with solutions.I can't seem to find it. Which number is it?   ;  Question 14.;  Sorry for the late response, I haven't had much time to check the forums recently (My internet wasn't working most of the time...)@hplusI did send the message sizeThis actually sends the mouse coordinates but until I get this error fixed, I'll just leave this as is(I am processing this message as the Mouse coordinates and not turret direction)details in the code's commentsvoid C_Tank::SetTurretDirection(bool fSend){    C_Pointf p = *Mouse;    TurretDirection.x = p.x;    TurretDirection.y = p.y;    TurretDirection.Normalize();    this->TurretAngle = TurretDirection.Angle();    /***********************************************************    ERROR HERE!!    if I add    fSend = false;    I stop recieving unrecognized packets    might have something to do with   g_Network.Send(&p.x, sizeof(double));   g_Network.Send(&p.y, sizeof(double));    if i replace those with   g_Network.Send(&this->TankPosition.x, sizeof(double));   g_Network.Send(&this->TankPosition.y, sizeof(double));    (the sending part of the C_Tank::MoveTank function)    I don't get unrecognized packets    ***********************************************************/    if (fSend)    {   g_Network.Send((char)(sizeof(char)+2*sizeof(double))); //message size: 1 char + 2 doubles   g_Network.Send(MsgID::TurretAngleChange); //angle change   std::cout<<"P = "<<p.x<<", "<<p.y<<std::endl;   g_Network.Send(&p.x, sizeof(double));   g_Network.Send(&p.y, sizeof(double));    }}The send functionsvoid C_Network::Send(std::string s){    SendBuffer += s;}/******************************************I thought the error would be within this part of my code so i tried several different ways of appending the stringThe commented parts were my previous attempts******************************************/void C_Network::Send(void * in, int size){    //SendBuffer += reinterpret_cast<char*>(in);    //SendBuffer += std::string(reinterpret_cast<char*>(in), size);    SendBuffer.append(reinterpret_cast<char*>(in), size);    std::cout<<reinterpret_cast<char*>(in)<<","<<*reinterpret_cast<double*>(in)<<std::endl;}//this one's implemented in the class declarationvoid Send(char c) { SendBuffer += c; }This is the function that processes the recv bufferfirst i take in the message size (stored in i)make sure i have everythingstore the message type in MsgTypeand then switch(MsgType)...void C_Network::ProcessRecv(){    if (RecvBuffer.empty())    {   return;    }    int i = (int)RecvBuffer[0]; //Message Size    while (i <= 1)    {   RecvBuffer.pop_front();   if (RecvBuffer.empty())  return;   i = RecvBuffer[0];    }    if (i > RecvBuffer.size()-1) //if we didnt recieve everything    {   //if Message size is greater than the buffer size - Message size   return;    }    RecvBuffer.pop_front(); //remove message size    char MsgType = RecvBuffer[0];    RecvBuffer.pop_front(); i--; //remove message type    switch (MsgType)    {   case MsgID::TankPositionChange://tank moved   {  //std::cout<<"(char)3"<<std::endl;  C_Pointf p;  char c[8];  for (int i = 0; i < 8; i++)  { c = RecvBuffer[0]; RecvBuffer.pop_front();  }  double *d = reinterpret_cast<double*>(c);  p.x = *d;  for (int i = 0; i < 8; i++)  { c = RecvBuffer[0]; RecvBuffer.pop_front();  }  d = reinterpret_cast<double*>(c);  p.y = *d;  EnemyTank[0].SetTankPosition(p);  break;   }   case MsgID::TurretAngleChange: //turret angle change   {  //std::cout<<"(char)2: ";  char c[sizeof(double)];  for (int i = 0; i < sizeof(double); i++)  { c = RecvBuffer[0]; RecvBuffer.pop_front();  }  //double *d = reinterpret_cast<double*>(c);  //EnemyMouse[0].x = *d;  EnemyMouse[0].x = *reinterpret_cast<double*>(c);  for (int i = 0; i < sizeof(double); i++)  { c = RecvBuffer[0]; RecvBuffer.pop_front();  }  //d = reinterpret_cast<double*>(c);  //EnemyMouse[0].y = *d;  EnemyMouse[0].y = *reinterpret_cast<double*>(c);  std::cout<<"EM[0] = "<<EnemyMouse[0].x<<", "<<EnemyMouse[0].y<<std::endl;  break;   }   //case 'm': //message   case MsgID::ChatMessage: //message   {  std::cout<<"Recieved Message: ";  for (i; i > 0; i--)  { putchar(RecvBuffer[0]); RecvBuffer.pop_front();  }  putchar('\n');  break;   }   default:   {  std::cerr<<"unrecognized packet: "<<(int)MsgType<<std::endl;  for (i; i > 0; i--)  { RecvBuffer.pop_front();  }  break;   }    }    return this->ProcessRecv();}I'm sure I'm processing the messages correctly...What are possible reasons for such output?   ;  Note that std::string may terminate the string where it finds a 0, even if you "add" more "data." Use a std::vector<> instead if you want to store all the data you put in.;  Thanks, I'll try that   