![]() |
| | #1 |
| ex-SPEEDCUBER Join Date: Dec 2005 Location: Canada
Posts: 265
| recving gibberish... It's my first time using async sockets I'm writing a game and I'm trying to make it send a message whenever the opponent moves I hardcoded it to send "mma" for debugging purposes and I'm recving the "mma"'s but once in a while, I get these strings of random(ish) chars within the "mma" string Screen shot the top right window is the data I'm recving I put a putchar('\n'); after each recv call I'm outputing the data right after I recv it so I know it's got nothing to do with not processing it properly It seems to have something to do with the recvbuffer's size What happens if the data received is larger than your buffer? Does recv stop recving once it encounters a \0? [edit]I just counted the chars, I get the D-" every 255th char and the recvbuffer is an array of 256 chars[/edit]
__________________ Please let me know if there's any part of my code I can change for optimization OS: Windows XP and Ubuntu IDE: wxDev-C++ and CodeBlocks Compiler: GNU GCC Last edited by h_howee; 09-17-2007 at 12:11 PM. |
| h_howee is offline | |
| | #2 |
| Sweet Join Date: Aug 2002 Location: Tucson, Arizona
Posts: 1,698
| What does your recv code look like? |
| prog-bman is offline | |
| | #3 |
| ex-SPEEDCUBER Join Date: Dec 2005 Location: Canada
Posts: 265
| Code: char temprecv[256] = {0};
int BytesSent;
case FD_READ:
{
if (recv(wParam, temprecv, sizeof(temprecv), 0) == 0)
{
std::cout<<"You opponent has left the game."<<std::endl;
PostQuitMessage(0);
}
std::cout<<temprecv<<std::endl;
std::string a(temprecv);
for (int i = 0; i < a.size(); i++)
{
RecvBuffer.push_back(a[i]);
}
this->ProcessRecv();
break;
}
__________________ Please let me know if there's any part of my code I can change for optimization OS: Windows XP and Ubuntu IDE: wxDev-C++ and CodeBlocks Compiler: GNU GCC |
| h_howee is offline | |
| | #4 |
| ex-SPEEDCUBER Join Date: Dec 2005 Location: Canada
Posts: 265
| damnit, I always find the solution right after i post here... Code: case FD_READ:
{
BytesSent = recv(wParam, temprecv, sizeof(temprecv), 0);
if (BytesSent == 0)
{
std::cout<<"You opponent has left the game."<<std::endl;
PostQuitMessage(0);
}
for (int i = 0; i < BytesSent; i++)
{
RecvBuffer.push_back(temprecv[i]);
}
this->ProcessRecv();
break;
}
__________________ Please let me know if there's any part of my code I can change for optimization OS: Windows XP and Ubuntu IDE: wxDev-C++ and CodeBlocks Compiler: GNU GCC |
| h_howee is offline | |
| | #5 |
| Sweet Join Date: Aug 2002 Location: Tucson, Arizona
Posts: 1,698
| Yep. Thats what I though the problem was also. |
| prog-bman is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Using inFile to read from TXT yields gibberish | Zzaacchh | C++ Programming | 4 | 08-05-2008 07:59 PM |
| How to avoid gibberish? | duffmckagan | C Programming | 8 | 06-24-2006 10:53 AM |
| Why is it gibberish? | ober | General Discussions | 11 | 11-10-2005 01:24 PM |